Class: Zold::Txns
- Inherits:
-
Object
- Object
- Zold::Txns
- Defined in:
- lib/zold/txns.rb
Overview
A collection of transactions
Defined Under Namespace
Classes: CantParse
Instance Method Summary collapse
- #fetch ⇒ Object
- #flush ⇒ Object
-
#initialize(file) ⇒ Txns
constructor
A new instance of Txns.
Constructor Details
#initialize(file) ⇒ Txns
Returns a new instance of Txns.
18 19 20 |
# File 'lib/zold/txns.rb', line 18 def initialize(file) @file = file end |
Instance Method Details
#fetch ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/zold/txns.rb', line 26 def fetch raise "Wallet file '#{@file}' is absent" unless File.exist?(@file) txns = [] i = 0 File.open(@file) do |f| until f.eof? line = f.readline i += 1 next if i < 5 next if line.strip.empty? txns << Txn.parse(line, i) end end raise CantParse, "Not enough lines in #{@file}, just #{i}" if i < 4 txns.sort end |
#flush ⇒ Object
22 23 24 |
# File 'lib/zold/txns.rb', line 22 def flush # nothing end |