Class: Tramway::Event::Events::Show::EventDecorator

Inherits:
Core::ApplicationDecorator
  • Object
show all
Defined in:
app/decorators/tramway/event/events/show/event_decorator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.collectionsObject



5
6
7
# File 'app/decorators/tramway/event/events/show/event_decorator.rb', line 5

def collections
  [:all]
end

Instance Method Details

#backgroundObject



18
19
20
# File 'app/decorators/tramway/event/events/show/event_decorator.rb', line 18

def background
  object.photo
end

#durationObject Also known as: tagline



22
23
24
25
26
27
28
29
30
31
32
# File 'app/decorators/tramway/event/events/show/event_decorator.rb', line 22

def duration
  return unless object.begin_date.present? || object.end_date.present?

  if object.begin_date.to_date == object.end_date.to_date
    I18n.l(object.begin_date, format: '%d %B %Y').to_s
  elsif object.begin_date.month == object.end_date.month
    "#{I18n.t('date.from')} #{I18n.l(object.begin_date, format: '%d')} #{I18n.t('date.to')} #{I18n.l(object.end_date, format: '%d %B %Y')}"
  else
    "#{I18n.t('date.from')} #{I18n.l(object.begin_date, format: '%d %B %Y')} #{I18n.t('date.to')} #{I18n.l(object.end_date, format: '%d %B %Y')}"
  end
end

#is_during?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'app/decorators/tramway/event/events/show/event_decorator.rb', line 63

def is_during?
  object.begin_date < DateTime.now && object.end_date > DateTime.now
end

#is_future?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'app/decorators/tramway/event/events/show/event_decorator.rb', line 59

def is_future?
  object.begin_date > DateTime.now
end

#is_past?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'app/decorators/tramway/event/events/show/event_decorator.rb', line 55

def is_past?
  object.end_date < DateTime.now
end

#partnersObject



34
35
36
37
38
39
40
41
42
# File 'app/decorators/tramway/event/events/show/event_decorator.rb', line 34

def partners
  if defined?(::Tramway::Partner)
    @partners ||= ::Tramway::Partner::Partnership.partnership_type.values.reduce({}) do |hash, partnership_type|
      hash.merge! partnership_type => (object.send(partnership_type.to_s.pluralize).map do |partner|
        Tramway::Partner::OrganizationFeatureDecorator.decorate partner
      end)
    end
  end
end

#responsible_personObject



46
47
48
49
50
51
52
53
# File 'app/decorators/tramway/event/events/show/event_decorator.rb', line 46

def responsible_person
  {
    title: Tramway::User::UserDecorator.decorate(object.creator)&.name,
    phone: (object.creator.phone if object.creator&.phone&.present?),
    email: (object.creator.email if object.creator&.email&.present?),
    social_networks: (object.creator.social_networks.active if object.creator.respond_to?(:social_networks))
  }
end