Class: Chillout::CreationsContainer
- Inherits:
-
Object
- Object
- Chillout::CreationsContainer
- Defined in:
- lib/chillout/creations_container.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](name) ⇒ Object
- #as_measurements(timestamp = Time.now) ⇒ Object
- #each(&proc) ⇒ Object
- #empty? ⇒ Boolean
- #increment!(class_name, value = 1) ⇒ Object
-
#initialize ⇒ CreationsContainer
constructor
A new instance of CreationsContainer.
- #key(name) ⇒ Object
- #merge(other_container) ⇒ Object
- #resource_keys ⇒ Object
Constructor Details
#initialize ⇒ CreationsContainer
Returns a new instance of CreationsContainer.
3 4 5 |
# File 'lib/chillout/creations_container.rb', line 3 def initialize @container = Hash.new {|hash, key| hash[key] = 0} end |
Instance Method Details
#==(other) ⇒ Object
35 36 37 38 |
# File 'lib/chillout/creations_container.rb', line 35 def ==(other) self.class == other.class && @container == other.instance_variable_get(:@container) end |
#[](name) ⇒ Object
12 13 14 15 |
# File 'lib/chillout/creations_container.rb', line 12 def [](name) key = key(name) @container[key] end |
#as_measurements(timestamp = Time.now) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/chillout/creations_container.rb', line 44 def as_measurements( = Time.now) = .iso8601 @container.each.map do |model_name, value| { series: model_name.to_s, tags: {}, timestamp: , values: { creations: value }, } end end |
#each(&proc) ⇒ Object
21 22 23 |
# File 'lib/chillout/creations_container.rb', line 21 def each(&proc) @container.each(&proc) end |
#empty? ⇒ Boolean
40 41 42 |
# File 'lib/chillout/creations_container.rb', line 40 def empty? @container.empty? end |
#increment!(class_name, value = 1) ⇒ Object
7 8 9 10 |
# File 'lib/chillout/creations_container.rb', line 7 def increment!(class_name, value=1) key = key(class_name) @container[key] += value end |
#key(name) ⇒ Object
17 18 19 |
# File 'lib/chillout/creations_container.rb', line 17 def key(name) name.to_sym end |
#merge(other_container) ⇒ Object
29 30 31 32 33 |
# File 'lib/chillout/creations_container.rb', line 29 def merge(other_container) for key in other_container.resource_keys increment!(key, other_container[key]) end end |
#resource_keys ⇒ Object
25 26 27 |
# File 'lib/chillout/creations_container.rb', line 25 def resource_keys @container.keys end |