class PaBillreader::CLI
Public Instance Methods
call()
click to toggle source
# File lib/pa_billreader/cli.rb, line 5 def call puts "-------------------------------" puts "Welcome to the PA bill reader!" puts "-------------------------------" puts "Loading bills now..." puts "-------------------------------" create_bills # binding.pry menu goodbye end
create_bill_details_all()
click to toggle source
# File lib/pa_billreader/cli.rb, line 28 def create_bill_details_all PaBillreader::Bill.all.each {|bill| attributes = PaBillreader::Scraper.scrape_bill_detail(bill.branch, bill.number) bill.add_bill_attributes(attributes) } end
create_bill_details_single(bill)
click to toggle source
# File lib/pa_billreader/cli.rb, line 35 def create_bill_details_single(bill) attributes = PaBillreader::Scraper.scrape_bill_detail(bill.branch, bill.number) bill.add_bill_attributes(attributes) end
create_bills()
click to toggle source
# File lib/pa_billreader/cli.rb, line 17 def create_bills PaBillreader::Scraper.scrape_bill_nums("H") #house bills puts "There are currently #{PaBillreader::Bill.house_bills.size} bills in the House" PaBillreader::Scraper.scrape_bill_nums("S") #senate bills puts "There are currently #{PaBillreader::Bill.senate_bills.size} bills in the Senate" end
display_bill_info(bill)
click to toggle source
# File lib/pa_billreader/cli.rb, line 103 def display_bill_info(bill) puts "#{display_branch(bill.branch)} Bill Number #{bill.number}: #{bill.short_title}" puts "Primary Sponsor: #{bill.prime_sponsor}" puts "Last Action: #{bill.last_action}" puts "Type 'Open Memo' to open memo in browser." if bill.memo_url puts "Type 'Open Full' to open full bill text in browser." if bill.full_text_url end
display_branch(abbrev)
click to toggle source
# File lib/pa_billreader/cli.rb, line 123 def display_branch(abbrev) return "Senate" if abbrev == "S" return "House" if abbrev == "H" end
get_valid_bill_num()
click to toggle source
# File lib/pa_billreader/cli.rb, line 83 def get_valid_bill_num input_num = "0" while !input_num.to_i.between?(1, PaBillreader::Bill.size) puts "Enter the number of the bill you'd like to view" puts "-------------------------------" input_num = gets.strip end input_num end
get_valid_branch()
click to toggle source
# File lib/pa_billreader/cli.rb, line 93 def get_valid_branch input_branch = "" while input_branch != "S" && input_branch != "H" puts "Would you like to see the senate or house bill?" puts "-------------------------------" input_branch = gets.strip.upcase[0,1] end input_branch end
goodbye()
click to toggle source
# File lib/pa_billreader/cli.rb, line 132 def goodbye puts "See you later for more bills bills bills!" end
list_bills()
click to toggle source
# File lib/pa_billreader/cli.rb, line 40 def list_bills puts "Here are all the current bills for Regular Session 2017-2018" puts "-------------------------------" puts "This may take a while..." puts "-------------------------------" create_bill_details_all PaBillreader::Bill.sorted! PaBillreader::Bill.all.each {|bill| puts bill.number puts bill.short_title } puts "-------------------------------" end
open_full(bill)
click to toggle source
# File lib/pa_billreader/cli.rb, line 115 def open_full(bill) open_in_browser(bill.full_text_url) end
open_in_browser(url)
click to toggle source
# File lib/pa_billreader/cli.rb, line 119 def open_in_browser(url) system("open '#{url}'") end
open_memo(bill)
click to toggle source
# File lib/pa_billreader/cli.rb, line 111 def open_memo(bill) open_in_browser(bill.memo_url) end
print_history()
click to toggle source
# File lib/pa_billreader/cli.rb, line 128 def print_history @@viewed_bills.each {|bill| display_bill_info(bill)} end