Class: Restwoods::LineParser
- Inherits:
-
Object
- Object
- Restwoods::LineParser
- Defined in:
- lib/restwoods/line_parser.rb
Constant Summary collapse
- PICKS =
{ java: /\A\s*\*/, erlang: /\A\s*%/, perl: /\A\s*#/ }
- COMMANDS =
/\A@(doc(\_state)?|res(\_(param|header|return|error|state|bind))?|cmd\_(def|use))\Z/
Instance Method Summary collapse
- #indentation ⇒ Object
-
#initialize(str, clazz) ⇒ LineParser
constructor
A new instance of LineParser.
- #parse ⇒ Object
Constructor Details
#initialize(str, clazz) ⇒ LineParser
Returns a new instance of LineParser.
7 8 9 10 11 |
# File 'lib/restwoods/line_parser.rb', line 7 def initialize(str, clazz) @clazz = clazz pick = PICKS[clazz] @str = pick.nil? ? str : str.gsub(pick, '') end |
Instance Method Details
#indentation ⇒ Object
23 24 25 |
# File 'lib/restwoods/line_parser.rb', line 23 def indentation @indentation ||= @str.match(/\A\s*/)[0].length end |
#parse ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/restwoods/line_parser.rb', line 13 def parse parts = @str.strip.split(/\s+/) command = parts[0].to_s.match(COMMANDS) if command.nil? || command[1].nil? { type: :joint, text: @str } else send(command[1], parts[1..-1], command) end end |