Class: Junoser::Display::ConfigStore

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

Constant Summary collapse

OFFSET =
'    '

Instance Attribute Summary collapse

Attributes included from Enumerable

#in_from, #in_group, #in_then

Instance Method Summary collapse

Methods included from Enumerable

#to_enum

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 = match(deactivated_line)

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

#each_with_inactive(str = '', &block) ⇒ Object



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

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

  str
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



54
55
56
# File 'lib/junoser/display/config_store.rb', line 54

def to_s
  each_with_inactive('', &method(:hash_item_to_s))
end