Class: SpsBill::Bill

Inherits:
Object
  • Object
show all
Includes:
BillParser
Defined in:
lib/sps_bill/bill.rb

Overview

SpsBill::Bill represents an individual SP Services PDF bill

It is initialised given a file name, and provides a range of accessors to get at individual data elements (e.g. electricity_usage)

Constant Summary

Constants included from BillParser

SpsBill::BillParser::ELECTRICITY_SERVICE_FOOTER, SpsBill::BillParser::ELECTRICITY_SERVICE_HEADER, SpsBill::BillParser::GAS_SERVICE_FOOTER, SpsBill::BillParser::GAS_SERVICE_HEADER, SpsBill::BillParser::WATER_SERVICE_FOOTER, SpsBill::BillParser::WATER_SERVICE_HEADER

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BillParser

#do_complete_parse, #errors, #parse_account_number, #parse_electricity_usage, #parse_gas_usage, #parse_invoice_date, #parse_invoice_month, #parse_total_amount, #parse_water_usage

Constructor Details

#initialize(source) ⇒ Bill

source is a file name or stream-like object



27
28
29
30
# File 'lib/sps_bill/bill.rb', line 27

def initialize(source)
  @source_file = source
  do_complete_parse
end

Instance Attribute Details

#account_numberObject (readonly)

accessors for the various bill components



14
15
16
# File 'lib/sps_bill/bill.rb', line 14

def 
  @account_number
end

#electricity_usageObject (readonly)

electricity_usage is an array of hashed values:

[{ kwh: float, rate: float, amount: float }]


18
19
20
# File 'lib/sps_bill/bill.rb', line 18

def electricity_usage
  @electricity_usage
end

#gas_usageObject (readonly)

gas_usage is an array of hashed values:

[{ kwh: float, rate: float, amount: float }]


21
22
23
# File 'lib/sps_bill/bill.rb', line 21

def gas_usage
  @gas_usage
end

#invoice_dateObject (readonly)

accessors for the various bill components



14
15
16
# File 'lib/sps_bill/bill.rb', line 14

def invoice_date
  @invoice_date
end

#invoice_monthObject (readonly)

accessors for the various bill components



14
15
16
# File 'lib/sps_bill/bill.rb', line 14

def invoice_month
  @invoice_month
end

#source_fileObject (readonly)

Returns the value of attribute source_file.



9
10
11
# File 'lib/sps_bill/bill.rb', line 9

def source_file
  @source_file
end

#total_amountObject (readonly)

accessors for the various bill components



14
15
16
# File 'lib/sps_bill/bill.rb', line 14

def total_amount
  @total_amount
end

#water_usageObject (readonly)

water_usage is an array of hashed values:

[{ cubic_m: float, rate: float, amount: float }]


24
25
26
# File 'lib/sps_bill/bill.rb', line 24

def water_usage
  @water_usage
end

Instance Method Details

#readerObject

Returns the PDF reader isntance



33
34
35
# File 'lib/sps_bill/bill.rb', line 33

def reader
  @reader ||= PDF::Reader::Turtletext.new(source_file) if source_file
end

#to_sObject

Return a pretty(-ish) text format of the core bill details



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/sps_bill/bill.rb', line 38

def to_s
  %(
Account number: #{}
Invoice date  : #{invoice_date}
Service month : #{invoice_month}
Total bill    : $#{total_amount}

Electricity Usage
-----------------
#{electricity_usage}

Gas Usage
---------
#{gas_usage}

Water Usage
-----------
#{water_usage}

    )
end