Class: Vgcal::MyCalendar
- Inherits:
-
Object
- Object
- Vgcal::MyCalendar
- Defined in:
- lib/vgcal/my_calendar.rb
Instance Method Summary collapse
- #events ⇒ Object
-
#initialize(start_date, end_date) ⇒ MyCalendar
constructor
A new instance of MyCalendar.
-
#invited_meetings(events) ⇒ Object
return: [[“朝会”, 0.5], [“daily scrum”, 0.25], [“SRE朝会”, 0.5], [“定例”, 1.0]].
-
#tasks(events) ⇒ Object
return: [[“daily scrum”, 0.25], [“SRE定例”, 1.0], [“test”, 2.0], [“task2”, 1.0]].
Constructor Details
#initialize(start_date, end_date) ⇒ MyCalendar
Returns a new instance of MyCalendar.
9 10 11 12 |
# File 'lib/vgcal/my_calendar.rb', line 9 def initialize(start_date, end_date) @start_date = start_date @end_date = end_date end |
Instance Method Details
#events ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vgcal/my_calendar.rb', line 14 def events service = Google::Apis::CalendarV3::CalendarService.new service. = Vgcal::Authorizer.new.credentials calendar_id = my_email_address service.list_events( calendar_id, max_results: 100, single_events: true, order_by: 'startTime', time_min: @start_date, time_max: @end_date ) end |
#invited_meetings(events) ⇒ Object
return: [[“朝会”, 0.5], [“daily scrum”, 0.25], [“SRE朝会”, 0.5], [“定例”, 1.0]]
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/vgcal/my_calendar.rb', line 50 def invited_meetings(events) tasks_hash = {} events.items.each do |e| next if valid_event?(e) # 単一のカレンダー内から自分が出席返答したイベントを探して計算 e.attendees&.each do |a| next if valid_attendee?(a) add_task_time(tasks_hash, e) end end tasks_hash.sort.to_a end |
#tasks(events) ⇒ Object
return: [[“daily scrum”, 0.25], [“SRE定例”, 1.0], [“test”, 2.0], [“task2”, 1.0]]
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/vgcal/my_calendar.rb', line 29 def tasks(events) tasks_hash = {} events.items.each do |e| if e.organizer&.self && !e.summary.start_with?(*hide_words) if all_day_event?(e.start.date) tasks_hash[e.summary] = 0 else task_time = (e.end.date_time - e.start.date_time).to_f * 24 # 1日の中で同じタスク名が複数あったら時間を集計する。例.午前と午後それぞれでAプロジェクトに1時間スケジュール if tasks_hash[e.summary] tasks_hash[e.summary] += task_time else tasks_hash[e.summary] = task_time end end end end tasks_hash.sort.to_a end |