Class: GCalendarReader::Core
- Inherits:
-
Object
- Object
- GCalendarReader::Core
- Defined in:
- lib/gcalcore.rb
Instance Attribute Summary collapse
-
#events ⇒ Object
Returns the value of attribute events.
-
#ical ⇒ Object
Returns the value of attribute ical.
-
#limit_date ⇒ Object
Returns the value of attribute limit_date.
-
#method ⇒ Object
Returns the value of attribute method.
-
#product_id ⇒ Object
Returns the value of attribute product_id.
-
#proxy_host ⇒ Object
Returns the value of attribute proxy_host.
-
#proxy_pass ⇒ Object
Returns the value of attribute proxy_pass.
-
#proxy_port ⇒ Object
Returns the value of attribute proxy_port.
-
#proxy_user ⇒ Object
Returns the value of attribute proxy_user.
-
#scale ⇒ Object
Returns the value of attribute scale.
-
#time_zone_name ⇒ Object
Returns the value of attribute time_zone_name.
-
#time_zone_offset ⇒ Object
Returns the value of attribute time_zone_offset.
-
#url ⇒ Object
Returns the value of attribute url.
-
#version ⇒ Object
Returns the value of attribute version.
-
#xml ⇒ Object
Returns the value of attribute xml.
Class Method Summary collapse
Instance Method Summary collapse
- #add_event(event, sortit = true) ⇒ Object
- #calendar_raw_data ⇒ Object
- #events_in_range(start_time, end_time) ⇒ Object
- #future_events ⇒ Object
-
#initialize(cal_url, proxy_host, proxy_port, proxy_user, proxy_pass, nro_dias) ⇒ Core
constructor
A new instance of Core.
- #parse ⇒ Object
- #parse! ⇒ Object
- #parse_from_ical ⇒ Object
- #parse_from_ical! ⇒ Object
- #parse_from_xml ⇒ Object
- #parse_from_xml! ⇒ Object
- #past_events ⇒ Object
- #source_format ⇒ Object
Constructor Details
#initialize(cal_url, proxy_host, proxy_port, proxy_user, proxy_pass, nro_dias) ⇒ Core
Returns a new instance of Core.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/gcalcore.rb', line 15 def initialize(cal_url, proxy_host, proxy_port, proxy_user, proxy_pass, nro_dias) self.events = [] unless cal_url.empty? self.url = cal_url self.proxy_host=proxy_host self.proxy_port=proxy_port self.proxy_user=proxy_user self.proxy_pass=proxy_pass self.limit_date=Time.now + nro_dias self.parse! end end |
Instance Attribute Details
#events ⇒ Object
Returns the value of attribute events.
12 13 14 |
# File 'lib/gcalcore.rb', line 12 def events @events end |
#ical ⇒ Object
Returns the value of attribute ical.
12 13 14 |
# File 'lib/gcalcore.rb', line 12 def ical @ical end |
#limit_date ⇒ Object
Returns the value of attribute limit_date.
12 13 14 |
# File 'lib/gcalcore.rb', line 12 def limit_date @limit_date end |
#method ⇒ Object
Returns the value of attribute method.
12 13 14 |
# File 'lib/gcalcore.rb', line 12 def method @method end |
#product_id ⇒ Object
Returns the value of attribute product_id.
12 13 14 |
# File 'lib/gcalcore.rb', line 12 def product_id @product_id end |
#proxy_host ⇒ Object
Returns the value of attribute proxy_host.
12 13 14 |
# File 'lib/gcalcore.rb', line 12 def proxy_host @proxy_host end |
#proxy_pass ⇒ Object
Returns the value of attribute proxy_pass.
12 13 14 |
# File 'lib/gcalcore.rb', line 12 def proxy_pass @proxy_pass end |
#proxy_port ⇒ Object
Returns the value of attribute proxy_port.
12 13 14 |
# File 'lib/gcalcore.rb', line 12 def proxy_port @proxy_port end |
#proxy_user ⇒ Object
Returns the value of attribute proxy_user.
12 13 14 |
# File 'lib/gcalcore.rb', line 12 def proxy_user @proxy_user end |
#scale ⇒ Object
Returns the value of attribute scale.
12 13 14 |
# File 'lib/gcalcore.rb', line 12 def scale @scale end |
#time_zone_name ⇒ Object
Returns the value of attribute time_zone_name.
12 13 14 |
# File 'lib/gcalcore.rb', line 12 def time_zone_name @time_zone_name end |
#time_zone_offset ⇒ Object
Returns the value of attribute time_zone_offset.
12 13 14 |
# File 'lib/gcalcore.rb', line 12 def time_zone_offset @time_zone_offset end |
#url ⇒ Object
Returns the value of attribute url.
12 13 14 |
# File 'lib/gcalcore.rb', line 12 def url @url end |
#version ⇒ Object
Returns the value of attribute version.
12 13 14 |
# File 'lib/gcalcore.rb', line 12 def version @version end |
#xml ⇒ Object
Returns the value of attribute xml.
12 13 14 |
# File 'lib/gcalcore.rb', line 12 def xml @xml end |
Class Method Details
.parse(cal_url) ⇒ Object
35 36 37 |
# File 'lib/gcalcore.rb', line 35 def self.parse(cal_url) self.new(cal_url) end |
Instance Method Details
#add_event(event, sortit = true) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/gcalcore.rb', line 28 def add_event(event, sortit=true) self.events = [] unless self.events.is_a?(Array) self.events << event @events.sort! {|a,b| a.start_time <=> b.start_time } if sortit event end |
#calendar_raw_data ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/gcalcore.rb', line 91 def calendar_raw_data # If you need to use a proxy: unless self.proxy_host.nil? response = Net::HTTP::Proxy(self.proxy_host, self.proxy_port, self.proxy_user, self.proxy_pass).get_response(URI.parse(self.url)) case response when Net::HTTPSuccess, Net::HTTPRedirection #puts "Data #{data}" return response.body else response.error! return nil end else response = Net::HTTP.get_response(URI.parse(self.url)) case response when Net::HTTPSuccess, Net::HTTPRedirection #puts "Data #{data}" return response.body else response.error! return nil end end end |
#events_in_range(start_time, end_time) ⇒ Object
87 88 89 |
# File 'lib/gcalcore.rb', line 87 def events_in_range(start_time, end_time) events.inject([]) {|in_range,e| e.start_time < end_time && e.finish_time > start_time ? in_range.push(e) : in_range} end |
#future_events ⇒ Object
77 78 79 80 |
# File 'lib/gcalcore.rb', line 77 def future_events t = DateTime.now events.inject([]) {|future,e| e.start_time > t ? future.push(e) : future} end |
#parse ⇒ Object
42 43 44 |
# File 'lib/gcalcore.rb', line 42 def parse self.dup.parse! end |
#parse! ⇒ Object
39 40 41 |
# File 'lib/gcalcore.rb', line 39 def parse! self.url =~ /\.ics(?:\?.+)?$/ ? self.parse_from_ical! : self.parse_from_xml! end |
#parse_from_ical ⇒ Object
69 70 71 |
# File 'lib/gcalcore.rb', line 69 def parse_from_ical self.dup.parse_from_ical end |
#parse_from_ical! ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/gcalcore.rb', line 53 def parse_from_ical! rawdata = self.calendar_raw_data cals = RiCal.parse_string(rawdata) cal = cals.first cal.events.each do |event| unless event.occurrences({:before => self.limit_date}).size > 1 self.add_event(event, false) # (disable sorting until done) else event.occurrences({:before => self.limit_date}).each do |ev| self.add_event(ev, false) # (disable sorting until done) end end end @events.reject! {|e| e.start_time.nil?} @events.sort! {|a,b| a.start_time <=> b.start_time } end |
#parse_from_xml ⇒ Object
49 50 51 |
# File 'lib/gcalcore.rb', line 49 def parse_from_xml self.dup.parse_from_xml! end |
#parse_from_xml! ⇒ Object
46 47 48 |
# File 'lib/gcalcore.rb', line 46 def parse_from_xml! return false # THIS IS NOT IMPLEMENTED YET!! end |
#past_events ⇒ Object
82 83 84 85 |
# File 'lib/gcalcore.rb', line 82 def past_events t = DateTime.now events.inject([]) {|past,e| e.start_time < t ? past.push(e) : past} end |
#source_format ⇒ Object
73 74 75 |
# File 'lib/gcalcore.rb', line 73 def source_format self.ical ? 'ical' : (self.xml ? 'xml' : nil) end |