Sha256: 67fe3ba65036f27fe1dfbbe6ebc3881beea9f3e6680455acfe39bd6d3bd46f2c

Contents?: true

Size: 628 Bytes

Versions: 16

Compression:

Stored size: 628 Bytes

Contents

class UserLocation < AbstractAdapter
  belongs_to :user
  belongs_to :location
  belongs_to :detectable, polymorphic: true

  validates_inclusion_of :detectable_type, in: %w(LocationBeacon LocationGps)

  default_scope { includes(:detectable).order("created_at desc") }

  def coords=(c) # convenience method to set coordinates by an array of [lat,lng,alt]
    self.lat = c[0]
    self.lng = c[1]
    self.alt = c[2]
  end

  def beacon
    detectable.is_a?(LocationBeacon) ? detectable : {}
  end

  def distance
    if location.gps && lat && lng
      location.gps.distance_from(lat,lng)
    else
      nil
    end
  end

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
introspective_grape-0.6.1 spec/dummy/app/models/user_location.rb
introspective_grape-0.5.7 spec/dummy/app/models/user_location.rb
introspective_grape-0.5.6 spec/dummy/app/models/user_location.rb
introspective_grape-0.5.5 spec/dummy/app/models/user_location.rb
introspective_grape-0.5.4 spec/dummy/app/models/user_location.rb
introspective_grape-0.5.2 spec/dummy/app/models/user_location.rb
introspective_grape-0.5.0 spec/dummy/app/models/user_location.rb
introspective_grape-0.4.3 spec/dummy/app/models/user_location.rb
introspective_grape-0.4.2 spec/dummy/app/models/user_location.rb
introspective_grape-0.4.1 spec/dummy/app/models/user_location.rb
introspective_grape-0.4.0 spec/dummy/app/models/user_location.rb
introspective_grape-0.3.9 spec/dummy/app/models/user_location.rb
introspective_grape-0.3.7 spec/dummy/app/models/user_location.rb
introspective_grape-0.3.6 spec/dummy/app/models/user_location.rb
introspective_grape-0.3.5 spec/dummy/app/models/user_location.rb
introspective_grape-0.3.3 spec/dummy/app/models/user_location.rb