Class: Event
Instance Attribute Summary collapse
-
#day ⇒ Object
readonly
Returns the value of attribute day.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#phase ⇒ Object
readonly
Returns the value of attribute phase.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#week ⇒ Object
readonly
Returns the value of attribute week.
Class Method Summary collapse
- .all ⇒ Object
- .current_directory ⇒ Object
- .nil_or_match(attribute_value, value_to_match) ⇒ Object
- .where(args) ⇒ Object
Instance Method Summary collapse
- #all_day? ⇒ Boolean
-
#initialize(attributes) ⇒ Event
constructor
A new instance of Event.
- #moment? ⇒ Boolean
- #start_time_military ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Event
Returns a new instance of Event.
8 9 10 11 12 13 14 15 |
# 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 |
Instance Attribute Details
#day ⇒ Object (readonly)
Returns the value of attribute day.
6 7 8 |
# File 'lib/dbc_today/models/event.rb', line 6 def day @day end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
6 7 8 |
# File 'lib/dbc_today/models/event.rb', line 6 def description @description end |
#end_time ⇒ Object (readonly)
Returns the value of attribute end_time.
6 7 8 |
# File 'lib/dbc_today/models/event.rb', line 6 def end_time @end_time end |
#phase ⇒ Object (readonly)
Returns the value of attribute phase.
6 7 8 |
# File 'lib/dbc_today/models/event.rb', line 6 def phase @phase end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
6 7 8 |
# File 'lib/dbc_today/models/event.rb', line 6 def start_time @start_time end |
#week ⇒ Object (readonly)
Returns the value of attribute week.
6 7 8 |
# File 'lib/dbc_today/models/event.rb', line 6 def week @week end |
Class Method Details
.all ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# 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 |
.current_directory ⇒ Object
74 75 76 |
# File 'lib/dbc_today/models/event.rb', line 74 def self.current_directory File. File.dirname(__FILE__) end |
.nil_or_match(attribute_value, value_to_match) ⇒ Object
69 70 71 72 |
# 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 |
.where(args) ⇒ Object
47 48 49 50 51 52 53 |
# 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 |
Instance Method Details
#all_day? ⇒ Boolean
17 18 19 20 21 |
# 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? ⇒ Boolean
23 24 25 26 |
# File 'lib/dbc_today/models/event.rb', line 23 def moment? start_time == end_time || end_time.nil? end |
#start_time_military ⇒ Object
28 29 30 |
# File 'lib/dbc_today/models/event.rb', line 28 def start_time_military in_military(start_time) end |