Class: MeetupScraper::CliMethods

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

Instance Method Summary collapse

Instance Method Details

#create_events_from_hashes(event_hashes) ⇒ Object

create event instances



24
25
26
# File 'lib/meetup_scraper/cli_methods.rb', line 24

def create_events_from_hashes(event_hashes)
  MeetupScraper::Event.create_from_collection(event_hashes)
end

#fetch_event_details(url) ⇒ Object

download the event’s details



29
30
31
# File 'lib/meetup_scraper/cli_methods.rb', line 29

def fetch_event_details(url)
  MeetupScraper::Scraper.fetch_event_details(url)
end

#get_user_inputObject

capture user input returning search url



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/meetup_scraper/cli_methods.rb', line 4

def get_user_input
  puts 'Search Meetup.com for events in your local area'
  puts 'Enter the meetup subject'
  subject = gets.chomp
  puts 'Enter your town'
  town = gets.chomp
  puts 'How many miles from your town are you willing to travel'
  miles = gets.chomp.to_i
  miles = 1 if miles == 0

  base_url = 'https://www.meetup.com/find/events/?allMeetups=false&keywords='
  "#{base_url}#{subject}&radius=#{miles}&userFreeForm=#{town}"
end

#pick_meetup_eventObject



46
47
48
49
50
51
52
# File 'lib/meetup_scraper/cli_methods.rb', line 46

def pick_meetup_event
    puts 'Enter the number of the event to view more details'
    puts "Enter '0' to search again"
    puts "To quit, enter 'exit'"
    puts 'What would you like to do?'
    gets.chomp
end

print event detatils



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/meetup_scraper/cli_methods.rb', line 34

def print_event(event)
  puts '------------------------------'
  puts "Title: #{event.title}"
  puts "Organiser: #{event.organiser}"
  puts "Date: #{event.date}"
  puts "Time: #{event.time}"
  puts "Number attending: #{event.num_attending}"
  puts "Address: #{event.address}"
  puts "Description: #{event.description}"
  puts '------------------------------'
end


54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/meetup_scraper/cli_methods.rb', line 54

def print_events
  MeetupScraper::Event.all.each_with_index do |event, i|
    puts "------------------------------"
    puts "#{i + 1}. #{event.title}"
    puts "Organiser: #{event.organiser}"
    puts "Date: #{event.date.slice(0, 10)}"
    puts "Time: #{event.time}"
    puts "Number attending: #{event.num_attending}"
    puts "Url: #{event.url}"
    puts "------------------------------"
  end
end

#search_meetup(url) ⇒ Object

fetch the meetup events



19
20
21
# File 'lib/meetup_scraper/cli_methods.rb', line 19

def search_meetup(url)
  MeetupScraper::Scraper.fetch_meetup_list(url)
end