Class: Zold::Txns

Inherits:
Object
  • Object
show all
Defined in:
lib/zold/txns.rb

Overview

A collection of transactions

Defined Under Namespace

Classes: CantParse

Instance Method Summary collapse

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

#fetchObject

Raises:



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

#flushObject



22
23
24
# File 'lib/zold/txns.rb', line 22

def flush
  # nothing
end