Class: PayoneerCsv::PdfReader

Inherits:
Object
  • Object
show all
Defined in:
lib/payoneer_csv/pdf_reader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ PdfReader

Returns a new instance of PdfReader.



6
7
8
# File 'lib/payoneer_csv/pdf_reader.rb', line 6

def initialize(file_path)
  @file_path = file_path
end

Instance Attribute Details

#file_pathObject (readonly)

Returns the value of attribute file_path.



4
5
6
# File 'lib/payoneer_csv/pdf_reader.rb', line 4

def file_path
  @file_path
end

Instance Method Details

#parse(row) ⇒ Object



27
28
29
# File 'lib/payoneer_csv/pdf_reader.rb', line 27

def parse(row)
  row.match /^(?<created_at>\d{1,2}\/\d{1,2}\/\d{4} \d{1,2}:\d{2}:\d{2} (AM|PM))\s(?<description>.+) (?<amount>-?(\d|,)+\.\d{2})\s+USD$/
end

#raw_dataObject



23
24
25
# File 'lib/payoneer_csv/pdf_reader.rb', line 23

def raw_data
  `ps2ascii #{file_path}`
end

#readObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/payoneer_csv/pdf_reader.rb', line 10

def read
  transactions = []

  raw_data.each_line do |row|
    match_data = parse(row)
    next unless match_data

    transactions << Transaction.new(match_data)
  end

  transactions
end