Sha256: a0d26732b2afbd1c72bf980eb44733e9842a33d11fbc0d8787d0c94f78c52907
Contents?: true
Size: 704 Bytes
Versions: 8
Compression:
Stored size: 704 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 result = {} by_type.each_pair { |key, value| result[key] = -value } Amount.new(-value, result) 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
8 entries across 8 versions & 1 rubygems