class SpsBill::Shell
Constants
- OPTIONS
command line options definition
Attributes
fileset[RW]
options[RW]
Public Class Methods
new(options)
click to toggle source
new
# File lib/sps_bill/shell.rb, line 28 def initialize(options) @fileset = ARGV @options = (options||{}).each{|k,v| {k => v} } end
usage()
click to toggle source
Usage message
# 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
Public Instance Methods
bills()
click to toggle source
# File lib/sps_bill/shell.rb, line 53 def bills @bills ||= SpsBill::BillCollection.load(fileset) end
export(dataset_selector)
click to toggle source
# 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)
click to toggle source
# File lib/sps_bill/shell.rb, line 68 def format_header(data) return if options[:raw] puts data.join(',') end
format_rows(data)
click to toggle source
# File lib/sps_bill/shell.rb, line 62 def format_rows(data) data.each do |row| puts row.join(',') end end
run()
click to toggle source
# File lib/sps_bill/shell.rb, line 33 def run if options[:help] or fileset.empty? self.class.usage return end case options[: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