class Ellen::Handlers::SyoboiCalendar

Public Instance Methods

list(message) click to toggle source
# File lib/ellen/handlers/syoboi_calendar.rb, line 13
def list(message)
  message.reply(description, code: true)
end

Private Instance Methods

channel_ids() click to toggle source
# File lib/ellen/handlers/syoboi_calendar.rb, line 43
def channel_ids
  ENV["SYOBOI_CALENDAR_CHANNEL_IDS"]
end
description() click to toggle source
# File lib/ellen/handlers/syoboi_calendar.rb, line 19
def description
  if programs.empty?
    "No programs found"
  else
    programs.sort_by(&:started_at).map do |program|
      count = " ##{program.count}" if program.count
      %<#{program.started_at.strftime("%Y-%m-%d %H:%M")} #{program.title.name}#{count} (#{program.channel.name})>
    end.join("\n")
  end
end
now() click to toggle source
# File lib/ellen/handlers/syoboi_calendar.rb, line 47
def now
  @now ||= Time.now
end
played_from() click to toggle source
# File lib/ellen/handlers/syoboi_calendar.rb, line 51
def played_from
  now
end
played_to() click to toggle source

04:00 ~ 28:00

# File lib/ellen/handlers/syoboi_calendar.rb, line 56
def played_to
  if now.hour >= 4
    now.tomorrow.beginning_of_day + 4.hour
  else
    now.beginning_of_day + 4.hour
  end
end
program_options() click to toggle source
# File lib/ellen/handlers/syoboi_calendar.rb, line 34
def program_options
  {
    played_from: played_from,
    played_to: played_to,
    channel_id: channel_ids,
    includes: [:channel, :title],
  }.reject {|key, value| value.nil? }
end
programs() click to toggle source
# File lib/ellen/handlers/syoboi_calendar.rb, line 30
def programs
  @programs ||= ::SyoboiCalendar::Client.new.programs(program_options)
end