Class: Bearclaws::Group
- Inherits:
-
Object
- Object
- Bearclaws::Group
- Defined in:
- lib/bearclaws/group.rb
Overview
A grouped representation of AWS charges
Instance Attribute Summary collapse
-
#charges ⇒ Array
An array of Bearclaws::Charge objects.
-
#name ⇒ String
The tag by which the charges are grouped.
Instance Method Summary collapse
-
#initialize(name, charges = []) ⇒ Group
constructor
A new instance of Group.
-
#subtotals ⇒ Float
The total costs for the tag broken out by :product_code.
-
#total ⇒ Float
The total cost of all the charges with group’s tag.
Constructor Details
#initialize(name, charges = []) ⇒ Group
Returns a new instance of Group.
13 14 15 16 |
# File 'lib/bearclaws/group.rb', line 13 def initialize(name, charges = []) self.name = name.to_sym self.charges = charges end |
Instance Attribute Details
#charges ⇒ Array
An array of Bearclaws::Charge objects
7 8 9 |
# File 'lib/bearclaws/group.rb', line 7 def charges @charges end |
#name ⇒ String
The tag by which the charges are grouped
7 8 9 |
# File 'lib/bearclaws/group.rb', line 7 def name @name end |
Instance Method Details
#subtotals ⇒ Float
The total costs for the tag broken out by :product_code
28 29 30 31 32 33 34 35 |
# File 'lib/bearclaws/group.rb', line 28 def subtotals x = {} charges.each do |r| x[r.product_code] ||= 0.to_f x[r.product_code] += r.total_cost.to_f end return x end |
#total ⇒ Float
The total cost of all the charges with group’s tag
21 22 23 |
# File 'lib/bearclaws/group.rb', line 21 def total charges.map { |x| x.total_cost.to_f }.inject(:+) end |