Class: AspireBudget::Models::Transaction
- Inherits:
-
Object
- Object
- AspireBudget::Models::Transaction
- Defined in:
- lib/aspire_budget/models/transaction.rb
Instance Attribute Summary collapse
-
#account ⇒ Object
readonly
Returns the value of attribute account.
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#inflow ⇒ Object
readonly
Returns the value of attribute inflow.
-
#memo ⇒ Object
readonly
Returns the value of attribute memo.
-
#outflow ⇒ Object
readonly
Returns the value of attribute outflow.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(date:, outflow:, inflow:, category:, account:, memo:, status:) ⇒ Transaction
constructor
rubocop:disable Metrics/ParameterLists.
-
#to_row(header) ⇒ Object
rubocop:enable Metrics/ParameterLists.
Constructor Details
#initialize(date:, outflow:, inflow:, category:, account:, memo:, status:) ⇒ Transaction
rubocop:disable Metrics/ParameterLists
22 23 24 25 26 27 28 29 30 |
# File 'lib/aspire_budget/models/transaction.rb', line 22 def initialize(date:, outflow:, inflow:, category:, account:, memo:, status:) @date = date.nil? ? Date.today : Utils.parse_date(date) @outflow = outflow.to_f @inflow = inflow.to_f @category = category @account = account @memo = memo @status = status end |
Instance Attribute Details
#account ⇒ Object (readonly)
Returns the value of attribute account.
8 9 10 |
# File 'lib/aspire_budget/models/transaction.rb', line 8 def account @account end |
#category ⇒ Object (readonly)
Returns the value of attribute category.
8 9 10 |
# File 'lib/aspire_budget/models/transaction.rb', line 8 def category @category end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
8 9 10 |
# File 'lib/aspire_budget/models/transaction.rb', line 8 def date @date end |
#inflow ⇒ Object (readonly)
Returns the value of attribute inflow.
8 9 10 |
# File 'lib/aspire_budget/models/transaction.rb', line 8 def inflow @inflow end |
#memo ⇒ Object (readonly)
Returns the value of attribute memo.
8 9 10 |
# File 'lib/aspire_budget/models/transaction.rb', line 8 def memo @memo end |
#outflow ⇒ Object (readonly)
Returns the value of attribute outflow.
8 9 10 |
# File 'lib/aspire_budget/models/transaction.rb', line 8 def outflow @outflow end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
8 9 10 |
# File 'lib/aspire_budget/models/transaction.rb', line 8 def status @status end |
Class Method Details
.from_row(header, row) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/aspire_budget/models/transaction.rb', line 10 def self.from_row(header, row) params = header.zip(row).to_h params.tap do |h| h[:date] = Utils.parse_date(h[:date]) h[:status] = Utils.parse_status(h[:status]) end new(**params) end |
Instance Method Details
#to_row(header) ⇒ Object
rubocop:enable Metrics/ParameterLists
33 34 35 36 37 38 39 40 41 |
# File 'lib/aspire_budget/models/transaction.rb', line 33 def to_row(header) header.map do |h| value = send(h) next Utils.serialize_date(value) if h == :date next Utils.serialize_status(value) if h == :status value end end |