Sha256: bfc0f4f844030238a35812f8c00cb85cd8ccb059fdb8733b05a715879e82fa13

Contents?: true

Size: 1006 Bytes

Versions: 13

Compression:

Stored size: 1006 Bytes

Contents

class Array
  def to_lng_lat
    self[0..1].map(&:to_f)
  end
end

class Hash
  def to_lng_lat
    raise "Hash must have at least 2 items" if self.size < 2
    [to_lng, to_lat]
  end

  def to_lat
    v = (Mongoid::Spacial.lat_symbols & self.keys).first
    return self[v].to_f if !v.nil? && self[v]
    raise "Hash must contain #{Mongoid::Spacial.lat_symbols.inspect} if ruby version is less than 1.9" if RUBY_VERSION.to_f < 1.9
    raise "Hash cannot contain #{Mongoid::Spacial.lng_symbols.inspect} as the second item if there is no #{Mongoid::Spacial.lat_symbols.inspect}" if Mongoid::Spacial.lng_symbols.index(self.keys[1])
    self.values[1].to_f
  end

  def to_lng
    v = (Mongoid::Spacial.lng_symbols & self.keys).first
    return self[v].to_f if !v.nil? && self[v]
    raise "Hash cannot contain #{Mongoid::Spacial.lat_symbols.inspect} as the first item if there is no #{Mongoid::Spacial.lng_symbols.inspect}" if Mongoid::Spacial.lat_symbols.index(self.keys[0])
    self.values[0].to_f
  end
end

Version data entries

13 entries across 13 versions & 3 rubygems

Version Path
mongoid_spacial-0.2.17 lib/mongoid_spacial/spacial/core_ext.rb
sig_mongoid_spacial-0.2.17 lib/mongoid_spacial/spacial/core_ext.rb
cb_mongoid_spacial-0.2.16 lib/mongoid_spacial/spacial/core_ext.rb
mongoid_spacial-0.2.16 lib/mongoid_spacial/spacial/core_ext.rb
mongoid_spacial-0.2.13 lib/mongoid_spacial/spacial/core_ext.rb
mongoid_spacial-0.2.12 lib/mongoid_spacial/spacial/core_ext.rb
mongoid_spacial-0.2.11 lib/mongoid_spacial/spacial/core_ext.rb
mongoid_spacial-0.2.10 lib/mongoid_spacial/spacial/core_ext.rb
mongoid_spacial-0.2.8 lib/mongoid_spacial/spacial/core_ext.rb
mongoid_spacial-0.2.7 lib/mongoid_spacial/spacial/core_ext.rb
mongoid_spacial-0.2.6 lib/mongoid_spacial/spacial/core_ext.rb
mongoid_spacial-0.2.5 lib/mongoid_spacial/spacial/core_ext.rb
mongoid_spacial-0.2.4 lib/mongoid_spacial/spacial/core_ext.rb