Sha256: ce5b1b800e52bf021e6283ef522cab2216c64f76417ab500ddeda5264c8d9f94

Contents?: true

Size: 1.17 KB

Versions: 7

Compression:

Stored size: 1.17 KB

Contents

require 'geocoder'

class Venue < ActiveRecord::Base
  belongs_to :organization
  has_one :event

  validates_presence_of :name
  
  attr_accessible :name, :address1, :address2, :city, :state, :zip, :time_zone, :lat, :long
  
  geocoded_by :full_street_address, :latitude => :lat, :longitude => :long

  after_save :run_geocode, :if => :address1_changed?
  after_save :refresh_show_stats, :if => :time_zone_changed?
  
  def address_as_string
    street_as_string + " " + city_state_zip_as_string
  end

  def street_as_string
    str = (address1 || "") + " " + (address2 || "")
    str.strip
  end
  
  def city_state_zip_as_string
    str = (city || "") + " " + (state || "") + " " + (zip || "")
    str.strip
  end
  
  def address_as_url_query
    URI::escape(street_as_string + " " + city_state_zip_as_string)
  end

  def full_street_address
    (address1 || "") + ", " + (address2 || "") + ", " + (city || "") +
      ", " + (state || "") + " " + (zip || "")
  end

  def refresh_show_stats
    unless self.event.nil?
      self.event.shows.each {|s| s.delay.refresh_stats }
    end
  end
  
  private

    def run_geocode
      Delayed::Job.enqueue(GeocodeAddressJob.new(self))
    end
  
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
artfully_ose-1.2.0 app/models/venue.rb
artfully_ose-1.2.0.beta.1 app/models/venue.rb
artfully_ose-1.2.0.alpha.2 app/models/venue.rb
artfully_ose-1.2.0.alpha.1 app/models/venue.rb
artfully_ose-1.2.0.pre.27 app/models/venue.rb
artfully_ose-1.2.0.pre.26 app/models/venue.rb
artfully_ose-1.2.0.pre.24 app/models/venue.rb