Class: MeetupScraper::CommandLineInterface

Inherits:
Object
  • Object
show all
Defined in:
lib/meetup_scraper/command_line_interface.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommandLineInterface

Returns a new instance of CommandLineInterface.



4
5
6
# File 'lib/meetup_scraper/command_line_interface.rb', line 4

def initialize
  @climethods = MeetupScraper::CliMethods.new
end

Instance Attribute Details

#climethodsObject (readonly)

Returns the value of attribute climethods.



2
3
4
# File 'lib/meetup_scraper/command_line_interface.rb', line 2

def climethods
  @climethods
end

Instance Method Details



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/meetup_scraper/command_line_interface.rb', line 27

def print_meetup_event
  input = self.climethods.pick_meetup_event
  if (input.to_i >= 1 && input.to_i <= MeetupScraper::Event.all.size)
    event = MeetupScraper::Event.all[input.to_i - 1]
    url = event.url
    # down load event's details, update event attributes & print event
    updated_details = self.climethods.fetch_event_details(url)
    updated_event = event.update_event_attributes(updated_details)
    self.climethods.print_event(updated_event)
    self.run_again
  elsif input == '0'
    self.run
  elsif input == 'exit'
    puts 'Good bye!'
  else
    puts 'Selection not recognised, try again'
    print_meetup_event
  end
end


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/meetup_scraper/command_line_interface.rb', line 15

def print_meetup_events
  events = MeetupScraper::Event.all
  while events.size < 1
    puts "Sorry, no matches found, try again."
    puts '------------------------------------'
    self.run
  end
  self.climethods.print_events
  self.print_meetup_event
  #self.run
end

#runObject



8
9
10
11
12
13
# File 'lib/meetup_scraper/command_line_interface.rb', line 8

def run
  url = self.climethods.get_user_input
  event_hashes = climethods.search_meetup(url)
  climethods.create_events_from_hashes(event_hashes)
  self.print_meetup_events
end

#run_againObject



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/meetup_scraper/command_line_interface.rb', line 47

def run_again
  puts "Enter '1' to view listing again or '0' to search again"
  input = gets.chomp
  if input.to_i == 1
    self.print_meetup_events
  elsif input == '0'
    self.run
  else
    puts 'Selection not recognised, try again' 
    run_again
  end
end