Class: SpsBill::Shell
- Inherits:
-
Object
- Object
- SpsBill::Shell
- Defined in:
- lib/sps_bill/shell.rb
Constant Summary collapse
- OPTIONS =
command line options definition
%w(help verbose csv+ raw+ data=s)
Instance Attribute Summary collapse
-
#fileset ⇒ Object
Returns the value of attribute fileset.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
-
.usage ⇒ Object
Usage message.
Instance Method Summary collapse
- #bills ⇒ Object
- #export(dataset_selector) ⇒ Object
- #format_header(data) ⇒ Object
- #format_rows(data) ⇒ Object
-
#initialize(options) ⇒ Shell
constructor
new
. - #run ⇒ Object
Constructor Details
#initialize(options) ⇒ Shell
new
28 29 30 31 |
# File 'lib/sps_bill/shell.rb', line 28 def initialize() @fileset = ARGV @options = (||{}).each{|k,v| {k => v} } end |
Instance Attribute Details
#fileset ⇒ Object
Returns the value of attribute fileset.
2 3 4 |
# File 'lib/sps_bill/shell.rb', line 2 def fileset @fileset end |
#options ⇒ Object
Returns the value of attribute options.
2 3 4 |
# File 'lib/sps_bill/shell.rb', line 2 def @options end |
Class Method Details
.usage ⇒ Object
Usage message
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/sps_bill/shell.rb', line 8 def self.usage puts <<-EOS SP Services Bill Scanner v#{SpsBill::Version::STRING} =================================== Usage: sps_bill [options] file-spec Command Options -r | --raw raw data format (without headers) -c | --csv output in CSV format (default) -d= | --data=[charges,electricity,gas,water,all] file-spec is a path to the PDF bill(s) to read. EOS end |
Instance Method Details
#bills ⇒ Object
53 54 55 |
# File 'lib/sps_bill/shell.rb', line 53 def bills @bills ||= SpsBill::BillCollection.load(fileset) end |
#export(dataset_selector) ⇒ Object
57 58 59 60 |
# File 'lib/sps_bill/shell.rb', line 57 def export(dataset_selector) format_header bills.headers(dataset_selector) format_rows bills.send(dataset_selector) end |
#format_header(data) ⇒ Object
68 69 70 71 |
# File 'lib/sps_bill/shell.rb', line 68 def format_header(data) return if [:raw] puts data.join(',') end |
#format_rows(data) ⇒ Object
62 63 64 65 66 |
# File 'lib/sps_bill/shell.rb', line 62 def format_rows(data) data.each do |row| puts row.join(',') end end |
#run ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/sps_bill/shell.rb', line 33 def run if [:help] or fileset.empty? self.class.usage return end case [:data] when /^c/ export(:total_amounts) when /^e/ export(:electricity_usages) when /^g/ export(:gas_usages) when /^w/ export(:water_usages) # when /^a/ else export(:all_data) end end |