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

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 Models::EventPublishable

#publish_event

Instance Attribute Details

#end_dateObject (readonly)



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

validates :end_date, presence: true

#nameObject (readonly)

Validations

Validations:



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

validates :name, presence: true

#start_dateObject (readonly)



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

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:



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

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:



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

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

.pastActiveRecord::Relation<TradeShow>

A relation of TradeShows that are past. Active Record Scope

Returns:

See Also:



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

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

.ransackable_associations(_auth_object = nil) ⇒ Object



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

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

.ransackable_attributes(_auth_object = nil) ⇒ Object

Ransack configuration



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

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:



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

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

.upcomingActiveRecord::Relation<TradeShow>

A relation of TradeShows that are upcoming. Active Record Scope

Returns:

See Also:



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

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

Instance Method Details

#date_range_displayObject



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

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:



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

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

#past?Boolean

Returns:

  • (Boolean)


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

def past?
  end_date < Date.current
end

#short_date_rangeObject



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

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)


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

def single_day?
  start_date == end_date
end

#upcoming?Boolean

Helper methods

Returns:

  • (Boolean)


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

def upcoming?
  end_date >= Date.current
end