Class: TradeShow

Inherits:
ApplicationRecord show all
Includes:
Models::Auditable
Defined in:
app/models/trade_show.rb

Overview

== Schema Information

Table name: trade_shows
Database name: primary

id :bigint not null, primary key
booth :string
end_date :date not null
location :string
name :string not null
staff :string
start_date :date not null
created_at :datetime not null
updated_at :datetime not null
logo_id :bigint

Indexes

index_trade_shows_on_logo_id (logo_id)

Foreign Keys

fk_rails_... (logo_id => digital_assets.id)

Constant Summary

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

Constants included from Schedulable

Schedulable::SIMPLE_FORM_OPTIONS

Instance Attribute Summary collapse

Belongs to collapse

Methods included from Models::Auditable

#creator, #updater

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Models::Auditable

#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record

Methods inherited from ApplicationRecord

ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#end_dateObject (readonly)



86
# File 'app/models/trade_show.rb', line 86

validates :end_date, presence: true

#nameObject (readonly)

Validations

Validations:



84
# File 'app/models/trade_show.rb', line 84

validates :name, presence: true

#start_dateObject (readonly)



85
# File 'app/models/trade_show.rb', line 85

validates :start_date, presence: true

Class Method Details

.by_yearActiveRecord::Relation<TradeShow>

A relation of TradeShows that are by year. Active Record Scope

Returns:

See Also:



92
# File 'app/models/trade_show.rb', line 92

scope :by_year, ->(year) { where('EXTRACT(YEAR FROM start_date) = ?', year) }

.chronologicalActiveRecord::Relation<TradeShow>

A relation of TradeShows that are chronological. Active Record Scope

Returns:

See Also:



93
# File 'app/models/trade_show.rb', line 93

scope :chronological, -> { order(start_date: :asc) }

.pastActiveRecord::Relation<TradeShow>

A relation of TradeShows that are past. Active Record Scope

Returns:

See Also:



91
# File 'app/models/trade_show.rb', line 91

scope :past, -> { where(end_date: ...Date.current).order(start_date: :desc) }

.ransackable_associations(_auth_object = nil) ⇒ Object



101
102
103
# File 'app/models/trade_show.rb', line 101

def self.ransackable_associations(_auth_object = nil)
  %w[logo]
end

.ransackable_attributes(_auth_object = nil) ⇒ Object

Ransack configuration



97
98
99
# File 'app/models/trade_show.rb', line 97

def self.ransackable_attributes(_auth_object = nil)
  %w[name location start_date end_date booth staff created_at updated_at]
end

.reverse_chronologicalActiveRecord::Relation<TradeShow>

A relation of TradeShows that are reverse chronological. Active Record Scope

Returns:

See Also:



94
# File 'app/models/trade_show.rb', line 94

scope :reverse_chronological, -> { order(start_date: :desc) }

.upcomingActiveRecord::Relation<TradeShow>

A relation of TradeShows that are upcoming. Active Record Scope

Returns:

See Also:



90
# File 'app/models/trade_show.rb', line 90

scope :upcoming, -> { where(end_date: Date.current..).order(start_date: :asc) }

Instance Method Details

#date_range_displayObject



118
119
120
121
122
123
124
125
126
127
128
# File 'app/models/trade_show.rb', line 118

def date_range_display
  if single_day?
    start_date.strftime('%b %-d, %Y')
  elsif start_date.year == end_date.year && start_date.month == end_date.month
    "#{start_date.strftime('%b %-d')} - #{end_date.strftime('%-d, %Y')}"
  elsif start_date.year == end_date.year
    "#{start_date.strftime('%b %-d')} - #{end_date.strftime('%b %-d, %Y')}"
  else
    "#{start_date.strftime('%b %-d, %Y')} - #{end_date.strftime('%b %-d, %Y')}"
  end
end

#logoImage

Associations

Returns:

See Also:



81
# File 'app/models/trade_show.rb', line 81

belongs_to :logo, class_name: 'Image', optional: true

#past?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'app/models/trade_show.rb', line 110

def past?
  end_date < Date.current
end

#short_date_rangeObject



130
131
132
133
134
135
136
# File 'app/models/trade_show.rb', line 130

def short_date_range
  if single_day?
    start_date.strftime('%b %-d')
  else
    "#{start_date.strftime('%b %-d')} - #{end_date.strftime('%b %-d')}"
  end
end

#single_day?Boolean

Returns:

  • (Boolean)


114
115
116
# File 'app/models/trade_show.rb', line 114

def single_day?
  start_date == end_date
end

#upcoming?Boolean

Helper methods

Returns:

  • (Boolean)


106
107
108
# File 'app/models/trade_show.rb', line 106

def upcoming?
  end_date >= Date.current
end