Class: Hutils::Parser
- Inherits:
-
Object
- Object
- Hutils::Parser
- Defined in:
- lib/hutils.rb
Instance Method Summary collapse
-
#initialize(str) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Constructor Details
#initialize(str) ⇒ Parser
Returns a new instance of Parser.
64 65 66 |
# File 'lib/hutils.rb', line 64 def initialize(str) @str = str end |
Instance Method Details
#parse ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/hutils.rb', line 68 def parse events = @str.split("\n").map { |line| normalize(line) } events.map! do |, time| pairs = .scan(/(?:['"](?:\\.|[^'"])*['"]|[^'" ])+/).map do |pair| key, value = pair.split("=") [key, value].each do |str| str.gsub!(/^['"]?(.*?)['"]?$/, '\1') if str end [key, value || true] end [Hash[pairs], time] end end |