Class: Parser
- Inherits:
-
Object
- Object
- Parser
- Defined in:
- lib/parser.rb
Instance Attribute Summary collapse
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(text) ⇒ Parser
constructor
A new instance of Parser.
- #match_backticks ⇒ Object
- #match_triple_backticks ⇒ Object
- #match_triple_backticks_sh ⇒ Object
- #parse ⇒ Object
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
#text ⇒ Object
Returns the value of attribute text.
2 3 4 |
# File 'lib/parser.rb', line 2 def text @text end |
Instance Method Details
#match_backticks ⇒ Object
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_backticks ⇒ Object
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_sh ⇒ Object
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 |
#parse ⇒ Object
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 |