Class: Junoser::Display::ConfigStore

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/junoser/display/config_store.rb

Constant Summary collapse

OFFSET =
'    '

Instance Method Summary collapse

Constructor Details

#initialize(depth = 0) ⇒ ConfigStore

Returns a new instance of ConfigStore.



10
11
12
13
# File 'lib/junoser/display/config_store.rb', line 10

def initialize(depth=0)
  @hash = {}
  @depth = depth
end

Instance Method Details

#push(str) ⇒ Object Also known as: <<



15
16
17
18
19
20
21
22
# File 'lib/junoser/display/config_store.rb', line 15

def push(str)
  store = self

  join_arg(str).split("\n").each_with_index do |element, index|
    store[element] ||= self.class.new(index+1)
    store = store[element]
  end
end

#to_sObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/junoser/display/config_store.rb', line 25

def to_s
  str = ''

  each do |k, v|
    if v.empty?
      str << OFFSET*@depth << "#{k};\n"
    else
      str << OFFSET*@depth << "#{k} {\n"
      str << v.to_s.chop << "\n"
      str << OFFSET*@depth << "}\n"
    end
  end

  str
end