Class: Amount

Inherits:
Object show all
Defined in:
lib/guerrilla_patch/aggregate_by_type/amount.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, by_type) ⇒ Amount

Returns a new instance of Amount.



3
4
5
6
# File 'lib/guerrilla_patch/aggregate_by_type/amount.rb', line 3

def initialize(value, by_type)
  @value = value
  @by_type = by_type
end

Instance Attribute Details

#by_typeObject (readonly)

Returns the value of attribute by_type.



2
3
4
# File 'lib/guerrilla_patch/aggregate_by_type/amount.rb', line 2

def by_type
  @by_type
end

#valueObject (readonly)

Returns the value of attribute value.



2
3
4
# File 'lib/guerrilla_patch/aggregate_by_type/amount.rb', line 2

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



8
9
10
# File 'lib/guerrilla_patch/aggregate_by_type/amount.rb', line 8

def ==(other)
  self.value == other.value && self.by_type == other.by_type
end

#divideObject



26
27
28
# File 'lib/guerrilla_patch/aggregate_by_type/amount.rb', line 26

def divide
  value.divide by_type
end

#inspectObject



12
13
14
15
16
17
# 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

#negativeObject



19
20
21
22
23
24
# 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