Sha256: a1b19c042a5e86ef08868091307186776be474af2269443b9ab7cc1d44d65d79

Contents?: true

Size: 1 KB

Versions: 94

Compression:

Stored size: 1 KB

Contents

class Event < ApplicationRecord
  default_scope -> { order(:starts_at) }
  scope :upcoming, -> { where('ends_at > ?', Time.zone.today) }
  scope :past, -> { where('starts_at < ?', Time.zone.today).reverse_order }

  geocoded_by :address
  before_validation :geocode

  has_many :sessions, dependent: :nullify

  validates :title, presence: true
  validates :description, presence: true
  validates :starts_at, presence: true
  validates :ends_at, presence: true
  validates :url, presence: true

  def self.search(search)
    key = "%#{search}%"
    columns = %w[title description city country]
    @events = Event.where(
      columns.map { |c| "#{c} ilike :search" }.join(' OR '),
      search: key
    ).upcoming
  end

  private

  def address
    # Provide the full country name to the geocoder,
    # otherwise it thinks that IL is Illinois, not Israel
    if country
      country = ISO3166::Country[self.country.downcase]
      country = country.name if country
    end

    [city, country].compact.join(', ')
  end
end

Version data entries

94 entries across 94 versions & 1 rubygems

Version Path
station-0.5.16 lib/nexmo_developer/app/models/event.rb
station-0.5.15 lib/nexmo_developer/app/models/event.rb
station-0.5.14 lib/nexmo_developer/app/models/event.rb
station-0.5.13 lib/nexmo_developer/app/models/event.rb
station-0.5.12 lib/nexmo_developer/app/models/event.rb
station-0.5.11 lib/nexmo_developer/app/models/event.rb
station-0.5.10 lib/nexmo_developer/app/models/event.rb
station-0.5.9 lib/nexmo_developer/app/models/event.rb
station-0.5.8 lib/nexmo_developer/app/models/event.rb
station-0.5.7 lib/nexmo_developer/app/models/event.rb
station-0.5.6 lib/nexmo_developer/app/models/event.rb
station-0.5.5 lib/nexmo_developer/app/models/event.rb
station-0.5.4 lib/nexmo_developer/app/models/event.rb
station-0.5.3 lib/nexmo_developer/app/models/event.rb
station-0.5.2 lib/nexmo_developer/app/models/event.rb
station-0.5.1 lib/nexmo_developer/app/models/event.rb
station-0.5.0 lib/nexmo_developer/app/models/event.rb
station-0.4.9 lib/nexmo_developer/app/models/event.rb
station-0.4.8 lib/nexmo_developer/app/models/event.rb
station-0.4.7 lib/nexmo_developer/app/models/event.rb