Class: ParseITC::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/parseitc/parser.rb

Direct Known Subclasses

TransactionParser

Constant Summary collapse

Version =
'0.1.5'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(files = []) ⇒ Parser

files can be either string or array



8
9
10
11
# File 'lib/parseitc/parser.rb', line 8

def initialize(files=[])
  @transactions = []
  add_files files
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *arguments) ⇒ Object (private)



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/parseitc/parser.rb', line 32

def method_missing(method_id, *arguments)
  match = /split_by_([_a-zA-Z]\w*)/.match(method_id.to_s)
  if match
    split_by(match)
  else
    match = /count_by_([_a-zA-Z]\w*)|numbers_by_([_a-zA-Z]\w*)/.match(method_id.to_s)
    if match
      count_by(match)
    else
      super
    end
  end
end

Instance Attribute Details

#transactionsObject

Returns the value of attribute transactions.



5
6
7
# File 'lib/parseitc/parser.rb', line 5

def transactions
  @transactions
end

Instance Method Details

#add_file(file) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/parseitc/parser.rb', line 19

def add_file file
  lines = File.readlines(file)
  lines.shift if lines.first.match(/^Provider/)
  lines.each do |xion|
    add_transaction xion
  end
end

#add_files(files) ⇒ Object



13
14
15
16
17
# File 'lib/parseitc/parser.rb', line 13

def add_files files
  [files].flatten.each do |file|
    add_file file
  end
end

#add_transaction(transaction) ⇒ Object



27
28
29
# File 'lib/parseitc/parser.rb', line 27

def add_transaction transaction
  @transactions << Transaction.new(transaction.split(/\t|\n/))
end