Class: TopCompanies::CompanyController
- Inherits:
-
Object
- Object
- TopCompanies::CompanyController
- Defined in:
- lib/top_companies/company_controller.rb
Constant Summary collapse
- BASE_URL =
"http://fortune.com"
Instance Method Summary collapse
- #display_company(index) ⇒ Object
- #intro ⇒ Object
- #list_companies ⇒ Object
- #make_companies ⇒ Object
- #run ⇒ Object
Instance Method Details
#display_company(index) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/top_companies/company_controller.rb', line 55 def display_company(index) company = TopCompanies::Company.all[index - 1] puts "#{company.name.upcase}".colorize(:color => :blue).bold puts " CEO".italic + ": #{company.ceo.name}" puts " Sector".italic + ": #{company.sector.name}" puts " Location".italic + ": #{company.location}" puts " Website".italic + ": #{company.website}" puts "----------------------" end |
#intro ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/top_companies/company_controller.rb', line 10 def intro puts "Welcome to Company Lookup App" puts "To list all of the Companies, enter 'list companies'" puts "To quit, type 'exit'" input = gets.strip until input == "list companies" || input == "exit" do puts "To list all of the Companies, enter 'list companies'" puts "To quit, type 'exit'" input = gets.strip end case input when "list companies" list_companies when "exit" exit 0 end puts "Please enter the number(s) of the company(ies) you would like to know more about (separated by ','):" number = gets.strip numbers = number.split(/\s*[,]\s*/) numbers.each do |index| company = TopCompanies::Company.all[index.to_i - 1] company_attributes_hash = TopCompanies::Scraper.scrape_profile_page(BASE_URL + company.slug) company.add_attributes(company_attributes_hash) end numbers.each do |index| display_company(index.to_i) end end |
#list_companies ⇒ Object
44 45 46 47 48 |
# File 'lib/top_companies/company_controller.rb', line 44 def list_companies TopCompanies::Company.all.each.with_index(1) do |company, index| puts "#{index}. #{company.name}" end end |
#make_companies ⇒ Object
50 51 52 53 |
# File 'lib/top_companies/company_controller.rb', line 50 def make_companies companies_array = TopCompanies::Scraper.scrape_index_page("http://fortune.com/fortune500/list/") TopCompanies::Company.create_from_collection(companies_array) end |
#run ⇒ Object
4 5 6 7 8 |
# File 'lib/top_companies/company_controller.rb', line 4 def run make_companies intro # add_attributes_to_companies end |