Class: Timely::Event
- Inherits:
-
Object
- Object
- Timely::Event
- Defined in:
- lib/timely/event.rb
Constant Summary collapse
- ATTRS =
%i[ id calendar_id external_id title description location start_time end_time all_day timezone recurrence_rule status organizer attendees my_status alarms metadata calendar_name calendar_color ].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #date_str ⇒ Object
- #duration_minutes ⇒ Object
- #end_date ⇒ Object
-
#initialize(attrs = {}) ⇒ Event
constructor
A new instance of Event.
- #start_date ⇒ Object
- #time_range_str ⇒ Object
- #title_str ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Event
Returns a new instance of Event.
12 13 14 15 16 17 |
# File 'lib/timely/event.rb', line 12 def initialize(attrs = {}) attrs.each do |key, value| sym = key.to_sym send(:"#{sym}=", value) if respond_to?(:"#{sym}=") end end |
Class Method Details
.from_h(hash) ⇒ Object
25 26 27 |
# File 'lib/timely/event.rb', line 25 def self.from_h(hash) new(hash) end |
.from_row(row) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/timely/event.rb', line 29 def self.from_row(row) attrs = {} row.each do |key, value| attrs[key.to_sym] = value end new(attrs) end |
Instance Method Details
#date_str ⇒ Object
67 68 69 70 |
# File 'lib/timely/event.rb', line 67 def date_str return "" unless start_time Time.at(start_time.to_i).strftime("%Y-%m-%d") end |
#duration_minutes ⇒ Object
37 38 39 40 |
# File 'lib/timely/event.rb', line 37 def duration_minutes return 0 unless start_time && end_time ((end_time.to_i - start_time.to_i) / 60.0).round end |
#end_date ⇒ Object
47 48 49 50 |
# File 'lib/timely/event.rb', line 47 def end_date return nil unless end_time Time.at(end_time.to_i).to_date end |
#start_date ⇒ Object
42 43 44 45 |
# File 'lib/timely/event.rb', line 42 def start_date return nil unless start_time Time.at(start_time.to_i).to_date end |
#time_range_str ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/timely/event.rb', line 52 def time_range_str return "All day" if all_day && all_day != 0 return "" unless start_time st = Time.at(start_time.to_i) result = st.strftime("%H:%M") if end_time et = Time.at(end_time.to_i) result += " - #{et.strftime('%H:%M')}" end result end |
#title_str ⇒ Object
72 73 74 |
# File 'lib/timely/event.rb', line 72 def title_str title || "(No title)" end |
#to_h ⇒ Object
19 20 21 22 23 |
# File 'lib/timely/event.rb', line 19 def to_h ATTRS.each_with_object({}) do |attr, hash| hash[attr] = send(attr) end end |