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 Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(depth = 0) ⇒ ConfigStore

Returns a new instance of ConfigStore.



12
13
14
15
16
# File 'lib/junoser/display/config_store.rb', line 12

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

Instance Attribute Details

#deactivatedObject

Returns the value of attribute deactivated.



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

def deactivated
  @deactivated
end

Instance Method Details

#deactivate(deactivated_line) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/junoser/display/config_store.rb', line 28

def deactivate(deactivated_line)
  statement, store = matched(deactivated_line)

  if statement
    if statement == deactivated_line
      store.deactivated = true
    else
      store.deactivate(deactivated_line.sub(/^#{statement} */, ''))
    end
  else
    statement, store = inverse_matched(deactivated_line)
    if statement
      store.deactivated = true
    end
  end
end

#each_with_inactive(&block) ⇒ Object



45
46
47
48
49
50
# File 'lib/junoser/display/config_store.rb', line 45

def each_with_inactive(&block)
  each do |k, v|
    k = "inactive: #{k}" if v.deactivated
    yield k, v
  end
end

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



18
19
20
21
22
23
24
25
# File 'lib/junoser/display/config_store.rb', line 18

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



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/junoser/display/config_store.rb', line 52

def to_s
  str = ''

  each_with_inactive 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