Class: SocialSnippet::TagParser

Inherits:
Object
  • Object
show all
Defined in:
lib/social_snippet/tag_parser.rb

Class Method Summary collapse

Class Method Details

.find_snip_tags(s) ⇒ Array

Find `@snip` tags from text

Parameters:

  • s (String or Array)

    parsed text

Returns:

  • (Array)

    found `@snip` tags with line_no


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/social_snippet/tag_parser.rb', line 9

def find_snip_tags(s)
  found_lines = []

  lines = get_lines(s)

  lines.each.with_index do |line, i|
    if ::SocialSnippet::Tag.is_snip_tag_line(line)
      found_lines.push(
        {
          :line_no => i,
          :tag => ::SocialSnippet::Tag.new(line),
        }
      )
    end
  end

  return found_lines
end

.find_snippet_tags(s) ⇒ Array

Find `@snippet` tags from text

Parameters:

  • s (String or Array)

    parsed text

Returns:

  • (Array)

    found `@snippet` tags with line_no


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/social_snippet/tag_parser.rb', line 32

def find_snippet_tags(s)
  found_lines = []

  lines = get_lines(s)

  lines.each.with_index do |line, i|
    if ::SocialSnippet::Tag.is_snippet_tag_line(line)
      found_lines.push(
        {
          :line_no => i,
          :tag => ::SocialSnippet::Tag.new(line),
        }
      )
    end
  end

  return found_lines
end

.get_lines(s) ⇒ Object


51
52
53
54
55
56
57
# File 'lib/social_snippet/tag_parser.rb', line 51

def get_lines(s)
  if s.is_a?(String)
    return s.split("\n")
  elsif s.is_a?(Array)
    return s
  end
end