Class: DoubleEntry::Aggregate
- Inherits:
-
Object
- Object
- DoubleEntry::Aggregate
- Defined in:
- lib/double_entry/aggregate.rb
Instance Attribute Summary collapse
-
#account ⇒ Object
readonly
Returns the value of attribute account.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#filter ⇒ Object
readonly
Returns the value of attribute filter.
-
#function ⇒ Object
readonly
Returns the value of attribute function.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#range ⇒ Object
readonly
Returns the value of attribute range.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Class Method Summary collapse
Instance Method Summary collapse
- #amount(force_recalculation = false) ⇒ Object
- #formatted_amount ⇒ Object
-
#initialize(function, account, code, options) ⇒ Aggregate
constructor
A new instance of Aggregate.
Constructor Details
#initialize(function, account, code, options) ⇒ Aggregate
Returns a new instance of Aggregate.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/double_entry/aggregate.rb', line 6 def initialize(function, account, code, ) @function = function.to_s raise "Function not supported" unless %w[sum count average].include?(@function) @account = account.to_s @code = code ? code.to_s : nil @options = @scope = [:scope] @range = [:range] @filter = [:filter] end |
Instance Attribute Details
#account ⇒ Object (readonly)
Returns the value of attribute account.
4 5 6 |
# File 'lib/double_entry/aggregate.rb', line 4 def account @account end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
4 5 6 |
# File 'lib/double_entry/aggregate.rb', line 4 def code @code end |
#filter ⇒ Object (readonly)
Returns the value of attribute filter.
4 5 6 |
# File 'lib/double_entry/aggregate.rb', line 4 def filter @filter end |
#function ⇒ Object (readonly)
Returns the value of attribute function.
4 5 6 |
# File 'lib/double_entry/aggregate.rb', line 4 def function @function end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/double_entry/aggregate.rb', line 4 def @options end |
#range ⇒ Object (readonly)
Returns the value of attribute range.
4 5 6 |
# File 'lib/double_entry/aggregate.rb', line 4 def range @range end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
4 5 6 |
# File 'lib/double_entry/aggregate.rb', line 4 def scope @scope end |
Class Method Details
.formatted_amount(function, amount) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/double_entry/aggregate.rb', line 31 def self.formatted_amount(function, amount) safe_amount = amount || 0 case function.to_s when 'count' safe_amount else Money.new(safe_amount) end end |
Instance Method Details
#amount(force_recalculation = false) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/double_entry/aggregate.rb', line 18 def amount(force_recalculation = false) if force_recalculation clear_old_aggregates calculate else retrieve || calculate end end |
#formatted_amount ⇒ Object
27 28 29 |
# File 'lib/double_entry/aggregate.rb', line 27 def formatted_amount Aggregate.formatted_amount(function, amount) end |