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.



35
36
37
# File 'lib/zold/txns.rb', line 35

def initialize(file)
  @file = file
end

Instance Method Details

#fetchObject

Raises:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/zold/txns.rb', line 43

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



39
40
41
# File 'lib/zold/txns.rb', line 39

def flush
  # nothing
end