class Amount

Attributes

by_type[R]
value[R]

Public Class Methods

new(value, by_type) click to toggle source
# File lib/guerrilla_patch/aggregate_by_type/amount.rb, line 3
def initialize(value, by_type)
  @value = value
  @by_type = by_type
end

Public Instance Methods

==(other) click to toggle source
# File lib/guerrilla_patch/aggregate_by_type/amount.rb, line 8
def ==(other)
  self.value == other.value && self.by_type == other.by_type
end
divide() click to toggle source
# File lib/guerrilla_patch/aggregate_by_type/amount.rb, line 26
def divide
  value.divide by_type
end
inspect() click to toggle source
# File lib/guerrilla_patch/aggregate_by_type/amount.rb, line 12
def inspect
  consists_of do |result|
    result.add value_display
    result.when(by_type_display != '') { ", #{by_type_display}"}
  end
end
negative() click to toggle source
# File lib/guerrilla_patch/aggregate_by_type/amount.rb, line 19
def negative
  result = {}
  by_type.each_pair { |key, value| result[key] = -value }

  Amount.new(-value, result)
end

Private Instance Methods

by_type_display() click to toggle source
# File lib/guerrilla_patch/aggregate_by_type/amount.rb, line 35
def by_type_display
  by_type.map { |key, value| "#{key} => #{value.to_f}" }.join(", ")
end
value_display() click to toggle source
# File lib/guerrilla_patch/aggregate_by_type/amount.rb, line 31
def value_display
  value.to_f
end