class Ruboty::Ragoon::Event

Attributes

date[RW]
events[R]

Public Class Methods

new(date = Date.today) click to toggle source
# File lib/ruboty/ragoon/event.rb, line 9
def initialize(date = Date.today)
  @date = date
  self.retrieve
end

Public Instance Methods

count() click to toggle source
# File lib/ruboty/ragoon/event.rb, line 26
def count
  @events.count
end
filter_events(&proc) click to toggle source
# File lib/ruboty/ragoon/event.rb, line 22
def filter_events(&proc)
  @events = @events.find_all { |event| proc.call(event) }
end
render(private: false, template: 'events') click to toggle source
# File lib/ruboty/ragoon/event.rb, line 18
def render(private: false, template: 'events')
  render_template(template, events: format(private), date: self.date)
end
retrieve() click to toggle source
# File lib/ruboty/ragoon/event.rb, line 14
def retrieve
  @events ||= ::Ragoon::Services::Schedule.new.schedule_get_events(::Ragoon::Services.start_and_end(date))
end

Private Instance Methods

event_plan_emoticon(event) click to toggle source
# File lib/ruboty/ragoon/event.rb, line 73
def event_plan_emoticon(event)
  case event[:plan].to_s.strip
  when '社内MTG'      then ':office:'
  when '来客'         then ':briefcase:'
  when '外出'         then ':runner:'
  when '休み'         then ':confetti_ball:'
  when 'メンテナンス' then ':wrench:'
  when '作業'         then ':art:'
  when '出張'         then ':bullettrain_side:'
  when '研修'         then ':school:'
  else                     ':memo:'
  end
end
format(private) click to toggle source
# File lib/ruboty/ragoon/event.rb, line 32
def format(private)
  @events.map { |event| format_event(event, private) }
end
format_event(event, private) click to toggle source
# File lib/ruboty/ragoon/event.rb, line 36
def format_event(event, private)
  plan = event[:plan].to_s != '' ? "【#{event[:plan].strip}】" : ''
  period = if event[:allday]
             '終日'
           else
             "#{format_time(event[:start_at])}〜#{format_time(event[:end_at])}"
           end
  if !private && event[:private]
    title = '予定あり'
    facilities = ''
    url = ''
  else
    title = event[:title]
    facilities = event[:facilities].join(', ')
    url = event[:url]
  end

  {
    id:         event[:id],
    plan:       plan,
    emoticon:   event_plan_emoticon(event),
    period:     period,
    title:      title,
    facilities: facilities,
    private:    event[:private],
    url:        url,
  }
end
format_time(time) click to toggle source
# File lib/ruboty/ragoon/event.rb, line 65
def format_time(time)
  if time.to_s == ''
    ''
  else
    Time.parse(time).localtime.strftime('%R')
  end
end