Class: Almanack::Event

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/almanack/event.rb

Instance Method Summary collapse

Instance Method Details

#descriptionObject



31
32
33
# File 'lib/almanack/event.rb', line 31

def description
  self[:description]&.force_encoding('UTF-8')
end

#end_dateObject

Deprecated in favour of end_time



45
46
47
# File 'lib/almanack/event.rb', line 45

def end_date
  deprecated :end_date, newer_method: :end_time
end

#end_timeObject



49
50
51
# File 'lib/almanack/event.rb', line 49

def end_time
  read_attribute :end_time, fallback: :end_date
end

#formatted_dateObject



5
6
7
8
# File 'lib/almanack/event.rb', line 5

def formatted_date
  warn "formatted_date is deprecated, please use formatted_duration instead"
  formatted_duration
end

#formatted_durationObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/almanack/event.rb', line 10

def formatted_duration
  formatted = "#{formatted_day(start_time)}"
  formatted << " at #{formatted_time(start_time)}" unless start_time.is_a?(Date)

  if end_time
    formatted << " to " unless is_date_ending_on_same_day?
    formatted << "#{formatted_day(end_time)} at " unless ends_on_same_day?
    formatted << formatted_time(end_time) unless end_time.is_a?(Date)
  end

  formatted
end

#locationObject



27
28
29
# File 'lib/almanack/event.rb', line 27

def location
  self[:location]&.force_encoding('UTF-8')
end

#serializedObject



53
54
55
56
57
# File 'lib/almanack/event.rb', line 53

def serialized
  each_pair.with_object({}) do |(attr, _), hash|
    hash[attr] = serialize_attribute(attr)
  end
end

#start_dateObject

Deprecated in favour of start_time



36
37
38
# File 'lib/almanack/event.rb', line 36

def start_date
  deprecated :start_date, newer_method: :start_time
end

#start_timeObject



40
41
42
# File 'lib/almanack/event.rb', line 40

def start_time
  read_attribute :start_time, fallback: :start_date
end

#titleObject



23
24
25
# File 'lib/almanack/event.rb', line 23

def title
  self[:title]&.force_encoding('UTF-8')
end