Module: Subledger::Domain::Value
Defined Under Namespace
Modules: ValueClass
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
Class Method Summary collapse
Instance Method Summary collapse
- #+(other) ⇒ Object
- #==(other) ⇒ Object
- #initialize(arg_amount = 0) ⇒ Object
- #to_s ⇒ Object (also: #inspect)
- #value ⇒ Object
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
23 24 25 |
# File 'lib/subledger/domain/value.rb', line 23 def amount @amount end |
Class Method Details
.included(base) ⇒ Object
9 10 11 |
# File 'lib/subledger/domain/value.rb', line 9 def self.included base base.extend ValueClass end |
Instance Method Details
#+(other) ⇒ Object
41 42 43 |
# File 'lib/subledger/domain/value.rb', line 41 def + other (Balance.new + value + other.value).value end |
#==(other) ⇒ Object
45 46 47 |
# File 'lib/subledger/domain/value.rb', line 45 def == other self.value.class == other.value.class and amount == other.amount end |
#initialize(arg_amount = 0) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/subledger/domain/value.rb', line 25 def initialize arg_amount=0 if arg_amount.nil? raise ValueError, 'amount may not be nil' end validate_amount(arg_amount) if arg_amount.respond_to?(:match) big_amount = BigDecimal arg_amount validate_sign big_amount validate_amount( amount_to_s big_amount ) @amount = big_amount end |
#to_s ⇒ Object Also known as: inspect
53 54 55 |
# File 'lib/subledger/domain/value.rb', line 53 def to_s "#{self.class.type}: #{amount_to_s @amount}" end |
#value ⇒ Object
49 50 51 |
# File 'lib/subledger/domain/value.rb', line 49 def value self end |