Class: MineConcerts
- Inherits:
-
Object
- Object
- MineConcerts
- Defined in:
- lib/mine_concerts.rb
Instance Attribute Summary collapse
-
#artists ⇒ Object
Returns the value of attribute artists.
-
#recommended_concerts ⇒ Object
Returns the value of attribute recommended_concerts.
Class Method Summary collapse
Instance Method Summary collapse
- #get_concerts(zip) ⇒ Object
-
#initialize(zip, file) ⇒ MineConcerts
constructor
A new instance of MineConcerts.
- #recommend_concerts(local_concerts) ⇒ Object
Constructor Details
#initialize(zip, file) ⇒ MineConcerts
Returns a new instance of MineConcerts.
36 37 38 39 40 41 42 |
# File 'lib/mine_concerts.rb', line 36 def initialize zip, file mine = MineTunes.new file @artists = mine.names_of_artists local_concerts = get_concerts zip @recommended_concerts = recommend_concerts local_concerts end |
Instance Attribute Details
#artists ⇒ Object
Returns the value of attribute artists.
14 15 16 |
# File 'lib/mine_concerts.rb', line 14 def artists @artists end |
#recommended_concerts ⇒ Object
Returns the value of attribute recommended_concerts.
14 15 16 |
# File 'lib/mine_concerts.rb', line 14 def recommended_concerts @recommended_concerts end |
Class Method Details
.run(commands) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/mine_concerts.rb', line 16 def self.run commands zip = ARGV.shift file = ARGV concerts = MineConcerts.new zip, file puts "RECOMMENDED UPCOMING CONCERTS" puts concerts.recommended_concerts.each do |event| artists = event.artists * ", " puts "#{event.date}" puts "#{artists}" puts "at the #{event.venue_name}" puts "#{event.venue_city}, #{event.venue_state} #{event.venue_zip}" puts "#{event.url}" puts end end |
Instance Method Details
#get_concerts(zip) ⇒ Object
44 45 46 47 48 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 76 77 78 79 80 |
# File 'lib/mine_concerts.rb', line 44 def get_concerts zip local_concerts = [] doc = Nokogiri::XML(open("http://api.jambase.com/search?zip=#{zip}&apikey=6dgm76ejvz2643kdq8mc379k")) doc.xpath('/JamBase_Data/event').each do |event| = {} event.xpath('artists').each do |artists| value = [] artists.children.xpath('artist_name').each do |artist_name| value << artist_name.inner_text end [:artists] = value end event.xpath('event_date').each do |item| value = item.inner_text [:date] = value end event.xpath('venue').each do |venue| venue.children.each do |item| key = item.name.downcase.gsub(" ", "_").to_sym value = item.inner_text [key] = value end end event.xpath('event_url').each do |item| value = item.inner_text [:url] = value end local_concerts << Event.new() end local_concerts end |
#recommend_concerts(local_concerts) ⇒ Object
82 83 84 |
# File 'lib/mine_concerts.rb', line 82 def recommend_concerts local_concerts local_concerts.select{ |event| event.artists.map { |artist| @artists.include?(artist) }.any? } end |