Class: SpsBill::Bill
- Inherits:
-
Object
- Object
- SpsBill::Bill
- 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
-
#account_number ⇒ Object
readonly
accessors for the various bill components.
-
#electricity_usage ⇒ Object
readonly
electricity_usage is an array of hashed values: [{ kwh: float, rate: float, amount: float }].
-
#gas_usage ⇒ Object
readonly
gas_usage is an array of hashed values: [{ kwh: float, rate: float, amount: float }].
-
#invoice_date ⇒ Object
readonly
accessors for the various bill components.
-
#invoice_month ⇒ Object
readonly
accessors for the various bill components.
-
#source_file ⇒ Object
readonly
Returns the value of attribute source_file.
-
#total_amount ⇒ Object
readonly
accessors for the various bill components.
-
#water_usage ⇒ Object
readonly
water_usage is an array of hashed values: [{ cubic_m: float, rate: float, amount: float }].
Instance Method Summary collapse
-
#initialize(source) ⇒ Bill
constructor
source
is a file name or stream-like object. -
#reader ⇒ Object
Returns the PDF reader isntance.
-
#to_s ⇒ Object
Return a pretty(-ish) text format of the core bill details.
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_number ⇒ Object (readonly)
accessors for the various bill components
14 15 16 |
# File 'lib/sps_bill/bill.rb', line 14 def account_number @account_number end |
#electricity_usage ⇒ Object (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_usage ⇒ Object (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_date ⇒ Object (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_month ⇒ Object (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_file ⇒ Object (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_amount ⇒ Object (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_usage ⇒ Object (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
#reader ⇒ Object
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_s ⇒ Object
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: #{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 |