Class: Bmf::Dialog::Parser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dialogObject (readonly)

Returns the value of attribute dialog.



8
9
10
# File 'lib/bmf-dialog/parser.rb', line 8

def dialog
  @dialog
end

#sectionsObject (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

#parseObject



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_hashObject



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_plistObject



32
33
34
# File 'lib/bmf-dialog/parser.rb', line 32

def to_plist
  to_hash.to_plist
end