Class: HouseFloorBills::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/house_floor_bills/cli.rb

Instance Method Summary collapse

Instance Method Details

#callObject



5
6
7
8
9
# File 'lib/house_floor_bills/cli.rb', line 5

def call
  welcome
  list_bills
  menu
end

#list_billsObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/house_floor_bills/cli.rb', line 16

def list_bills
  s = HouseFloorBills::Scraper.new
  @schedule = s.scrape

  puts "\n\n-------------------------------------------".green
  puts "#{@schedule.title}".green
  puts "-------------------------------------------\n ".green

  @schedule.bills.each.with_index(1) do |bill, i|
    puts "#{i}." + " #{bill.number}".blue + " - #{bill.name}"
  end
end


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/house_floor_bills/cli.rb', line 49

def menu
  input = nil

  while input != "exit"
    puts "\nEnter command (type '" + "usage".red + "' for help):"
    print "> "
    input = gets.strip.downcase

    if input.to_i.between?(1, @schedule.bills.size)
      print_bill(@schedule.find_bill(input))
    elsif input == "usage"
      print_commands
    elsif input =~ /open \d/
      system("open #{@schedule.find_bill(input.split.last).url}")
    elsif input =~ /pdf \d/
      system("open #{@schedule.find_bill(input.split.last).pdf}")
    elsif input == "list"
      list_bills
    elsif input == "live"
      system("open https://live.house.gov/")
    elsif input == "exit"
      puts "šŸ’Ø"
    else
      puts "Invalid input."
    end
  end
end


29
30
31
32
33
34
35
36
37
38
# File 'lib/house_floor_bills/cli.rb', line 29

def print_bill(the_bill)
  puts "\n[#{the_bill.number}] #{the_bill.name}"
  puts "----------------------------------------------------------------------\n "
  puts "Status: #{the_bill.status}"
  puts "Sponsor: #{the_bill.sponsor}"
  puts "Committees: #{the_bill.committees}"
  puts "URL: #{the_bill.url}"
  puts "PDF: #{the_bill.pdf}"
  puts "Summary: #{the_bill.summary}"
end


40
41
42
43
44
45
46
47
# File 'lib/house_floor_bills/cli.rb', line 40

def print_commands
  puts "\nEnter a number between '" + "1-#{@schedule.bills.length}".red + "' for more info on corresponding bill."
  puts "Enter '" + "open 1-#{@schedule.bills.length}".red + "' to open bill page in browser."
  puts "Enter '" + "pdf 1-#{@schedule.bills.length}".red + "' to open bill PDF in browser."
  puts "Enter '" + "live".red + "' to watch the U.S. House of Representatives live"
  puts "Enter '" + "list".red + "' to see the list of bills again."
  puts "Enter '" + "exit".red + "' to exit program."
end

#welcomeObject



11
12
13
14
# File 'lib/house_floor_bills/cli.rb', line 11

def welcome
  puts "\nšŸ› " + " House Floor Bills ".blue + "šŸ›"
  puts "A simple CLI app to display the bills up for consideration on the U.S. House floor this week."
end