Class: ParameterCollection
- Inherits:
-
Object
- Object
- ParameterCollection
- Defined in:
- lib/hiera_browser/parameters.rb
Overview
A collection of Parameters, based on Arrays
Instance Method Summary collapse
- #<<(parameter) ⇒ ParameterCollection
- #[](index) ⇒ Object
- #collection ⇒ Array
-
#count ⇒ Fixnum
The number of Parameters in the ParameterCollection.
-
#include?(param) ⇒ TrueClass, FalseClass
True if this ParameterCollection includes a Parameter.
- #initialize ⇒ void constructor
-
#keys ⇒ Array
All keys in this ParameterCollection.
-
#to_h ⇒ Hash
The parameter collection condensed to a Hash, multiple values for the same key condensed into an Array, all keys duplicated.
Constructor Details
#initialize ⇒ void
4 5 6 |
# File 'lib/hiera_browser/parameters.rb', line 4 def initialize @collection = collection end |
Instance Method Details
#<<(parameter) ⇒ ParameterCollection
20 21 22 23 24 |
# File 'lib/hiera_browser/parameters.rb', line 20 def << (parameter) collection << parameter dedupe! self end |
#[](index) ⇒ Object
13 14 15 16 |
# File 'lib/hiera_browser/parameters.rb', line 13 def [](index) stripped_index = index.sub(/^::/,'') collection.select{|param| param.key == stripped_index }.map{|param|param.value} end |
#collection ⇒ Array
9 10 11 |
# File 'lib/hiera_browser/parameters.rb', line 9 def collection @collection || [] end |
#count ⇒ Fixnum
Returns the number of Parameters in the ParameterCollection.
40 41 42 |
# File 'lib/hiera_browser/parameters.rb', line 40 def count collection.count end |
#include?(param) ⇒ TrueClass, FalseClass
Returns True if this ParameterCollection includes a Parameter.
33 34 35 36 37 |
# File 'lib/hiera_browser/parameters.rb', line 33 def include?(param) truth = false collection.each{|p| truth = true if p == param} truth end |
#keys ⇒ Array
Returns all keys in this ParameterCollection.
27 28 29 |
# File 'lib/hiera_browser/parameters.rb', line 27 def keys collection.map{|param| param.key}.uniq end |
#to_h ⇒ Hash
Returns the parameter collection condensed to a Hash, multiple values for the same key condensed into an Array, all keys duplicated.
46 47 48 49 50 51 |
# File 'lib/hiera_browser/parameters.rb', line 46 def to_h self.keys.inject({}){|a, k| a[k] = self[k] a[Parameter.top_scope(k)] = self[k] a } end |