class Event

Attributes

day[R]
description[R]
end_time[R]
phase[R]
start_time[R]
week[R]

Public Class Methods

all() click to toggle source
# File lib/dbc_today/models/event.rb, line 32
def self.all
  list = []
  
  CSV.foreach(
    "#{current_directory}/../data/schedule.csv",
    headers: true,
    header_converters: :symbol,
    skip_blanks: true
  ) do |row|
    list << Event.new(row)
  end

  list
end
new(attributes) click to toggle source
# File lib/dbc_today/models/event.rb, line 8
def initialize(attributes)
  @phase = attributes.fetch(:phase)
  @week = attributes.fetch(:week)
  @day = attributes.fetch(:day)
  @description = attributes.fetch(:description)
  @start_time = attributes.fetch(:start_time)
  @end_time = attributes.fetch(:end_time)
end
where(args) click to toggle source
# File lib/dbc_today/models/event.rb, line 47
def self.where(args)
  all.select { |event|
    nil_or_match(event.phase, args[:phase]) &&
      nil_or_match(event.week, args[:week]) &&
      nil_or_match(event.day, args[:day])
  }.sort_by { |e| e.start_time_military }
end

Private Class Methods

current_directory() click to toggle source
# File lib/dbc_today/models/event.rb, line 74
def self.current_directory
  File.expand_path File.dirname(__FILE__)    
end
nil_or_match(attribute_value, value_to_match) click to toggle source
# File lib/dbc_today/models/event.rb, line 69
def self.nil_or_match(attribute_value, value_to_match)
  attribute_value.nil? ||
    attribute_value.include?(value_to_match)
end

Public Instance Methods

all_day?() click to toggle source
# File lib/dbc_today/models/event.rb, line 17
def all_day?
  start_time.downcase == 'all day' ||
    (starts_at_day_start? &&
    ends_at_day_end?)
end
moment?() click to toggle source
# File lib/dbc_today/models/event.rb, line 23
def moment?
  start_time == end_time ||
    end_time.nil?
end
start_time_military() click to toggle source
# File lib/dbc_today/models/event.rb, line 28
def start_time_military
  in_military(start_time)
end

Private Instance Methods

ends_at_day_end?() click to toggle source
# File lib/dbc_today/models/event.rb, line 63
def ends_at_day_end?
  return false if end_time.nil?

  end_time.start_with?('6:00p', '6p')
end
starts_at_day_start?() click to toggle source
# File lib/dbc_today/models/event.rb, line 57
def starts_at_day_start?
  return false if start_time.nil?

  start_time.start_with?('9:00a', '9a')
end