Class: ConcertCalendar
- Inherits:
-
Object
- Object
- ConcertCalendar
- Defined in:
- lib/concert_calendar.rb
Constant Summary collapse
- VERSION =
'0.1.0'
- CONFIG =
YAML.load_file(File.join(File.dirname(__FILE__), "../config/config.yml"))
Instance Attribute Summary collapse
-
#calendar ⇒ Object
Returns the value of attribute calendar.
-
#concerts ⇒ Object
Returns the value of attribute concerts.
Class Method Summary collapse
Instance Method Summary collapse
- #convert_to_ical(concerts) ⇒ Object
- #create_ics(ical) ⇒ Object
-
#initialize ⇒ ConcertCalendar
constructor
A new instance of ConcertCalendar.
- #upload_ics ⇒ Object
Constructor Details
#initialize ⇒ ConcertCalendar
Returns a new instance of ConcertCalendar.
30 31 32 33 34 |
# File 'lib/concert_calendar.rb', line 30 def initialize concerts = MineConcerts.new CONFIG['zip'], CONFIG['itunes_library'] create_ics convert_to_ical(concerts) upload_ics end |
Instance Attribute Details
#calendar ⇒ Object
Returns the value of attribute calendar.
20 21 22 |
# File 'lib/concert_calendar.rb', line 20 def calendar @calendar end |
#concerts ⇒ Object
Returns the value of attribute concerts.
20 21 22 |
# File 'lib/concert_calendar.rb', line 20 def concerts @concerts end |
Class Method Details
.run(args) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/concert_calendar.rb', line 22 def self.run args ConcertCalendar.new puts "Your calendar was successfully created and uploaded to #{CONFIG['server']}" puts "A copy of your calendar has been placed in #{CONFIG['local_path']}" puts "Rock on!" end |
Instance Method Details
#convert_to_ical(concerts) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/concert_calendar.rb', line 36 def convert_to_ical concerts calendar = Icalendar::Calendar.new concerts.recommended_concerts.each do |concert| event = calendar.event event. = DateTime.now event.summary = concert.artists * ", " event.description = concert.url event.location = "#{concert.venue_name}\n#{concert.venue_city}, #{concert.venue_state} #{concert.venue_zip}" # For now, this application assumes that all concerts start at 7:00 PM and end at 11:00 PM due to API LIMITATIONS (see README/PROBLEMS) start_time = "7:00 PM" end_time = "11:00 PM" event.start = DateTime.parse(concert.date + " " + start_time) event.end = DateTime.parse(concert.date + " " + end_time) end calendar = calendar.to_ical end |
#create_ics(ical) ⇒ Object
55 56 57 58 59 |
# File 'lib/concert_calendar.rb', line 55 def create_ics ical ics = File.new(CONFIG['local_path'] + CONFIG['filename'] + '.ics', 'w') ics.write(ical) ics.close end |
#upload_ics ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/concert_calendar.rb', line 61 def upload_ics ftp = Net::FTP.new(CONFIG['server'], CONFIG['username'], CONFIG['password']) ftp.passive = CONFIG['passive?'] ftp.chdir(CONFIG['remote_path']) if CONFIG['remote_path'] ftp.puttextfile(CONFIG['local_path'] + CONFIG['filename'] + '.ics', CONFIG['filename'] + '.ics') ftp.close end |