Sha256: 82815af4e2a12d7c410de486e1251f89b0f54ab9c8cf390fa0d22c6f53a5875d

Contents?: true

Size: 628 Bytes

Versions: 2

Compression:

Stored size: 628 Bytes

Contents

class Amount
  attr_reader :value, :by_type
  def initialize(value, by_type)
    @value = value
    @by_type = by_type
  end

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

  def inspect
    consists_of do |result|
      result.add value_display
      result.when(by_type_display != '') { ", #{by_type_display}"}
    end
  end

  def negative
    Amount.new(-value, by_type)
  end

  def divide
    value.divide by_type
  end

  private
  def value_display
    value.to_f
  end

  def by_type_display
    by_type.map { |key, value| "#{key} => #{value.to_f}" }.join(", ")
  end
end #Amount

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
guerrilla_patch-2.8.1 lib/guerrilla_patch/aggregate_by_type/amount.rb
guerrilla_patch-2.8.0 lib/guerrilla_patch/aggregate_by_type/amount.rb