Class: UEMLParser

Inherits:
Object
  • Object
show all
Defined in:
lib/ueml.rb

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ UEMLParser



2
3
4
5
6
# File 'lib/ueml.rb', line 2

def initialize(file)
  @file = file
  @sections = {}
  @current_section = nil
end

Instance Method Details

#parseObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ueml.rb', line 8

def parse
  File.readlines(@file).each_with_index do |line, index|
    line.strip!
  
    next if line.start_with?("//")
  
    if line.start_with?(">")
      @current_section = line[1..].strip
      @sections[@current_section] = {}
    else
      if line.end_with?(";")
        key, value = line.chomp(";").split("=", 2).map(&:strip)
        @sections[@current_section][key] = value
      end
    end
  end
end

#sectionsObject



26
27
28
# File 'lib/ueml.rb', line 26

def sections
  @sections
end