class SocialSnippet::TagParser

Public Class Methods

find_no_tags(s) click to toggle source
# File lib/social_snippet/tag_parser.rb, line 23
def find_no_tags(s)
  find_lines(s) {|line| Tag.is_no_tag_line?(line) }
end
find_snip_tags(s) click to toggle source

Find ‘@snip` tags from text

@param s [String or Array] parsed text @return [Array] found ‘@snip` tags with line_no

# File lib/social_snippet/tag_parser.rb, line 11
def find_snip_tags(s)
  find_lines(s) {|line| Tag.is_snip_tag_line(line) }
end
find_snippet_tags(s) click to toggle source

Find ‘@snippet` tags from text

@param s [String or Array] parsed text @return [Array] found ‘@snippet` tags with line_no

# File lib/social_snippet/tag_parser.rb, line 19
def find_snippet_tags(s)
  find_lines(s) {|line| Tag.is_snippet_tag_line(line) }
end

Private Class Methods

find_lines(s, &comparator) click to toggle source
# File lib/social_snippet/tag_parser.rb, line 29
def find_lines(s, &comparator)
  get_lines(s).each.with_index.inject([]) do |found_lines, (line, i)|
    if comparator.call(line)
      found_lines.push(
        {
          :line_no => i,
          :tag => Tag.new(line),
        }
      )
    end
    found_lines
  end
end
get_lines(s) click to toggle source
# File lib/social_snippet/tag_parser.rb, line 43
def get_lines(s)
  if s.is_a?(::String)
    s.split($/)
  elsif s.is_a?(::Array)
    s
  elsif s.is_a?(::Enumerator)
    s
  else
    raise "error unknown data"
  end
end