Class: Parser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Parser

Returns a new instance of Parser.



4
5
6
# File 'lib/parser.rb', line 4

def initialize(text)
  @text = text
end

Instance Attribute Details

#textObject

Returns the value of attribute text.



2
3
4
# File 'lib/parser.rb', line 2

def text
  @text
end

Instance Method Details

#match_backticksObject



14
15
16
17
18
# File 'lib/parser.rb', line 14

def match_backticks
  match_backticks = text.scan(/`(.*?)`/).flatten
  text.gsub!(/`.*?`/, '')
  match_backticks
end

#match_triple_backticksObject



20
21
22
23
24
# File 'lib/parser.rb', line 20

def match_triple_backticks
  triple_backtick_content = text.scan(/```\s*(.*?)\s*```/m).flatten
  text.gsub!(/```\s*.*?\s```/m, '')
  triple_backtick_content
end

#match_triple_backticks_shObject



8
9
10
11
12
# File 'lib/parser.rb', line 8

def match_triple_backticks_sh
  triple_sh = text.scan(/```sh\s*(.*?)\s*```/m).flatten
  text.gsub!(/```sh\s*.*?\s*```/m, '')
  triple_sh
end

#parseObject



26
27
28
29
30
# File 'lib/parser.rb', line 26

def parse
  matches = match_triple_backticks_sh + match_triple_backticks + match_backticks
  matches.reject!(&:empty?)
  matches
end