Class: Transaction::Parser
- Inherits:
-
Object
- Object
- Transaction::Parser
- Includes:
- Transaction
- Defined in:
- lib/transactions/main.rb
Overview
Public: Initializes a Transaction::Parser object. A ‘ledger.yaml’ file must exist in the current working directory.
Examples
require 'transactions'
# read the ledger.yaml file into a Transaction::Parser object
t = Transaction::Parser.new
Returns nothing
Constant Summary
Constants included from Transaction
Instance Method Summary collapse
-
#initialize ⇒ Parser
constructor
A new instance of Parser.
Methods included from Transaction
#parse, #transaction_balance, #transaction_command, #transaction_print, #transaction_register
Constructor Details
#initialize ⇒ Parser
Returns a new instance of Parser.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/transactions/main.rb', line 15 def initialize = Options.new. @default_ledger = 'ledger.yaml' if [:file] ledger = File.read [:file] else if File.exists? File.(@default_ledger) ledger = File.read(File.(@default_ledger)) else abort "There is no 'ledger.yaml' file in the current directory." end end @ledger = YAML::load ledger if ledger != "" @ledger = [] if ledger == "" @date = Time.now.strftime "%Y/%m/%d" if [:sort] == 'tran' # sort by transaction @ledger.sort_by! { |h| h['transaction'] } elsif [:sort] == 'date' # sort by date @ledger.sort_by! { |h| h['date'] } end end |