Class: Clian::Config::List
- Includes:
- Enumerable
- Defined in:
- lib/clian/config.rb
Overview
Parse Array object in YAML
Instance Attribute Summary
Attributes inherited from Element
Instance Method Summary collapse
- #<<(conf) ⇒ Object
- #[](key) ⇒ Object (also: #get_subnode)
- #each ⇒ Object
-
#initialize(item_class, array = []) ⇒ List
constructor
A new instance of List.
-
#to_hash ⇒ Object
XXX: actually, it returns a Array.
Methods inherited from Element
create_from_yaml_file, create_from_yaml_string, define_syntax, #get_value, syntax, #to_yaml
Constructor Details
#initialize(item_class, array = []) ⇒ List
Returns a new instance of List.
149 150 151 152 153 154 155 156 |
# File 'lib/clian/config.rb', line 149 def initialize(item_class, array = []) @original_hash = array @configs = [] (array || []).each do |value| item = item_class.new(value) @configs << item end end |
Instance Method Details
#<<(conf) ⇒ Object
164 165 166 |
# File 'lib/clian/config.rb', line 164 def <<(conf) @configs << conf end |
#[](key) ⇒ Object Also known as: get_subnode
158 159 160 |
# File 'lib/clian/config.rb', line 158 def [](key) @configs.find {|c| c.name == key} end |
#each ⇒ Object
172 173 174 175 176 |
# File 'lib/clian/config.rb', line 172 def each @configs.each do |conf| yield conf end end |
#to_hash ⇒ Object
XXX: actually, it returns a Array
168 169 170 |
# File 'lib/clian/config.rb', line 168 def to_hash # XXX: actually, it returns a Array return @configs.map {|c| c.respond_to?(:to_hash) ? c.to_hash : c.to_s} end |