Class: Bmf::Dialog::Parser
- Inherits:
-
Object
- Object
- Bmf::Dialog::Parser
- Defined in:
- lib/bmf-dialog/parser.rb
Instance Attribute Summary collapse
-
#dialog ⇒ Object
readonly
Returns the value of attribute dialog.
-
#sections ⇒ Object
readonly
Returns the value of attribute sections.
Instance Method Summary collapse
-
#initialize(dialog) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
- #to_hash ⇒ Object
- #to_plist ⇒ Object
Constructor Details
#initialize(dialog) ⇒ Parser
Returns a new instance of Parser.
10 11 12 13 |
# File 'lib/bmf-dialog/parser.rb', line 10 def initialize(dialog) @dialog = dialog @sections = {} end |
Instance Attribute Details
#dialog ⇒ Object (readonly)
Returns the value of attribute dialog.
8 9 10 |
# File 'lib/bmf-dialog/parser.rb', line 8 def dialog @dialog end |
#sections ⇒ Object (readonly)
Returns the value of attribute sections.
8 9 10 |
# File 'lib/bmf-dialog/parser.rb', line 8 def sections @sections end |
Instance Method Details
#parse ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/bmf-dialog/parser.rb', line 15 def parse dialog.split(/-+>/).each do |section| next if section.strip.empty? key = section.lines.first.strip dialog_parser = DialogParser.new(section) dialog_parser.parse @sections[key] = dialog_parser end self end |
#to_hash ⇒ Object
28 29 30 |
# File 'lib/bmf-dialog/parser.rb', line 28 def to_hash Hash[@sections.map { |k,v| [k, v.to_a] }] end |
#to_plist ⇒ Object
32 33 34 |
# File 'lib/bmf-dialog/parser.rb', line 32 def to_plist to_hash.to_plist end |