Module: Ecm::OpeningTimes::Entry::Times
- Included in:
- Ecm::OpeningTimes::Entry
- Defined in:
- app/models/ecm/opening_times/entry.rb
Instance Method Summary collapse
- #close_at(format: default_time_format) ⇒ Object
- #close_at=(time) ⇒ Object
- #default_time_format ⇒ Object
- #open_all_day ⇒ Object
- #open_all_day=(open_all_day) ⇒ Object
- #open_all_day? ⇒ Boolean
- #open_at(format: default_time_format) ⇒ Object
- #open_at=(time) ⇒ Object
- #opening_times ⇒ Object
Instance Method Details
#close_at(format: default_time_format) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'app/models/ecm/opening_times/entry.rb', line 39 def close_at(format: default_time_format) return nil if read_attribute(:close_at).nil? if format.nil? time = read_attribute(:close_at) else time = Time.at((read_attribute(:close_at) || 0) * 60).utc.strftime(format) end time == '00:00' ? '24:00' : time end |
#close_at=(time) ⇒ Object
22 23 24 25 26 27 28 |
# File 'app/models/ecm/opening_times/entry.rb', line 22 def close_at=(time) if time.to_s =~ /([0-9]{2}):([0-9]{2})/ write_attribute(:close_at, _time_to_minutes_since_midnight($~[1], $~[2])) else super end end |
#default_time_format ⇒ Object
10 11 12 |
# File 'app/models/ecm/opening_times/entry.rb', line 10 def default_time_format DEFAULT_TIME_FORMAT end |
#open_all_day ⇒ Object
64 65 66 |
# File 'app/models/ecm/opening_times/entry.rb', line 64 def open_all_day open_at == '00:00' && close_at == '24:00' end |
#open_all_day=(open_all_day) ⇒ Object
57 58 59 60 61 62 |
# File 'app/models/ecm/opening_times/entry.rb', line 57 def open_all_day=(open_all_day) if ActiveRecord::Type::Boolean.new.cast(open_all_day) == true self.open_at = '00:00' self.close_at = '24:00' end end |
#open_all_day? ⇒ Boolean
68 69 70 |
# File 'app/models/ecm/opening_times/entry.rb', line 68 def open_all_day? open_all_day end |
#open_at(format: default_time_format) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'app/models/ecm/opening_times/entry.rb', line 30 def open_at(format: default_time_format) return nil if read_attribute(:open_at).nil? if format.nil? read_attribute(:open_at) else Time.at((read_attribute(:open_at) || 0) * 60).utc.strftime(format) end end |
#open_at=(time) ⇒ Object
14 15 16 17 18 19 20 |
# File 'app/models/ecm/opening_times/entry.rb', line 14 def open_at=(time) if time.to_s =~ /([0-9]{2}):([0-9]{2})/ write_attribute(:open_at, _time_to_minutes_since_midnight($~[1], $~[2])) else super end end |
#opening_times ⇒ Object
49 50 51 52 53 54 55 |
# File 'app/models/ecm/opening_times/entry.rb', line 49 def opening_times if open_all_day? { open_at: '00:00', close_at: '24:00' } else { open_at: open_at, close_at: close_at } end end |