Class: TF1Converter::Config

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

Class Method Summary collapse

Class Method Details

.load(path) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/tf1_converter/config.rb', line 6

def self.load(path)
  last_key = nil
  current_control = nil
  CSV.read(path).each do |row|
    if last_key == 'INPUT'
      @input = row[0]
    elsif last_key == 'OUTPUT'
      @output = row[0]
    elsif last_key == 'ICON_PATH'
      @icon_path = row[0]
    elsif last_key == 'ICONS'
      @icons = {}
      current_control = 'ICONS'
    elsif last_key == 'COLORS'
      @colors = {}
      current_control = 'COLORS'
    end

    if current_control == 'ICONS'
      if row.empty?
        current_control = nil
      else
        @icons[row[0]] = {
          'icon' => row[1],
          'meaning' => row[2], 
          'name' => row[3] 
        }
      end
    elsif current_control == 'COLORS'
      if row.empty?
        current_control = nil
      else
        @colors[row[0]] = row[1]
      end
    end

    last_key = row[0]
  end
end