Class: Junoser::Display::ConfigStore
- Inherits:
-
Object
- Object
- Junoser::Display::ConfigStore
- Extended by:
- Forwardable
- Defined in:
- lib/junoser/display/config_store.rb
Constant Summary collapse
- OFFSET =
' '
Instance Attribute Summary collapse
-
#deactivated ⇒ Object
Returns the value of attribute deactivated.
Instance Method Summary collapse
- #deactivate(deactivated_line) ⇒ Object
- #each_with_inactive(&block) ⇒ Object
-
#initialize(depth = 0) ⇒ ConfigStore
constructor
A new instance of ConfigStore.
- #push(str) ⇒ Object (also: #<<)
- #to_s ⇒ Object
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
#deactivated ⇒ Object
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_s ⇒ Object
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 |