Class: Bearclaws::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/bearclaws/group.rb

Overview

A grouped representation of AWS charges

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, charges = []) ⇒ Group

Returns a new instance of Group.

Parameters:

  • name (String)

    The tag by which the charges are grouped

  • charges (Array) (defaults to: [])

    An array of Bearclaws::Charge objects



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

#chargesArray

An array of Bearclaws::Charge objects

Returns:

  • (Array)

    the current value of charges



7
8
9
# File 'lib/bearclaws/group.rb', line 7

def charges
  @charges
end

#nameString

The tag by which the charges are grouped

Returns:

  • (String)

    the current value of name



7
8
9
# File 'lib/bearclaws/group.rb', line 7

def name
  @name
end

Instance Method Details

#subtotalsFloat

The total costs for the tag broken out by :product_code

Returns:

  • (Float)


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

#totalFloat

The total cost of all the charges with group’s tag

Returns:

  • (Float)


21
22
23
# File 'lib/bearclaws/group.rb', line 21

def total
  charges.map { |x| x.total_cost.to_f }.inject(:+)
end