class Faktura::PDF

Constants

SIGNATURES

Attributes

amount[R]
content[R]
currency[R]
date[R]
filename[R]
overlay[R]
provider[R]

Public Class Methods

new(filename) click to toggle source
# File lib/faktura/pdf.rb, line 11
def initialize(filename)
  @filename = filename
  @content = read
  @date = nil
  @provider = nil
  @currency = nil
  @overlay = false

  analyze
end

Public Instance Methods

analyze() click to toggle source
# File lib/faktura/pdf.rb, line 33
def analyze
  SIGNATURES.each do |prv, opt|
    if content =~ opt[:name]
      @provider = prv
      @currency = opt[:currency]
      @overlay = opt[:overlay] || false

      if opt.has_key? :date and date_m = content.match(opt[:date])
        @date = date_m[1]
      end

      if opt.has_key? :amount and amount_m = content.match(opt[:amount])
        @amount = amount_m[1]
      end

    end
  end
end
read() click to toggle source
# File lib/faktura/pdf.rb, line 22
def read
  begin
    IO.popen(['pdftotext', @filename, '-']) do |io|
      io.read
    end
  rescue Errno::ENOENT => e
    STDERR.puts "#{e.message}. Make sure you have poppler-utils installed (sudo apt install poppler-utils)"
    ''
  end
end
to_s() click to toggle source
# File lib/faktura/pdf.rb, line 129
def to_s
  "#{provider} (#{date}) #{currency}#{amount or '???'}"
end