Class: Sutazekarate::TimetableEntry
- Inherits:
-
Object
- Object
- Sutazekarate::TimetableEntry
- Includes:
- ActiveModel::Attributes, ActiveModel::Model, ActiveModel::Serializers::JSON
- Defined in:
- lib/sutazekarate/timetable_entry.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.build(entry_element, categories: []) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sutazekarate/timetable_entry.rb', line 23 def self.build(entry_element, categories: []) title = entry_element.children.first.text.strip time_range_raw = entry_element.children.last.text.strip time_range_match = time_range_raw.match(/(\d+:\d+) - (\d+:\d+)/) time_range = Time.zone.parse(time_range_match[1])..Time.zone.parse(time_range_match[2]) category = categories.find do |category| category.name == title end TimetableEntry.new( category:, title:, time_range:, ) end |
Instance Method Details
#serializable_hash(options = nil) ⇒ Object
11 12 13 |
# File 'lib/sutazekarate/timetable_entry.rb', line 11 def serializable_hash( = nil) super.merge(time_begin:, time_end:).except('time_range') end |
#time_begin ⇒ Object
15 16 17 |
# File 'lib/sutazekarate/timetable_entry.rb', line 15 def time_begin time_range.begin end |
#time_end ⇒ Object
19 20 21 |
# File 'lib/sutazekarate/timetable_entry.rb', line 19 def time_end time_range.end end |