Sha256: 64911b64be40655b751cfce6085c4874611b9e21cfd2a87ea07b58d037cdab2b

Contents?: true

Size: 697 Bytes

Versions: 3

Compression:

Stored size: 697 Bytes

Contents

module Reality
  class Coord < Geo::Coord
    def timezone
      Util.require_optional('wheretz', 'Please install `wheretz` gem in order to have offline timezones')
      WhereTZ.get(lat, lng)
    end

    def distance(other)
      other = coerce_to_coord(other)
      Reality::Measure['km'].new(super(other) / 1000.0)
    end

    private

    def coerce_to_coord(val)
      case val
      when Geo::Coord
        other
      when Entity
        (val['coordinates'] || val['coordinates location']) or
          fail ArgumentError, "#{val} seem not hold any coordinates information"
      else
        fail ArgumentError, "#{val.class} can't be coerced to coordinates"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
reality-0.1.0.alpha3 lib/reality/coord.rb
reality-0.1.0.alpha2 lib/reality/coord.rb
reality-0.1.0.alpha lib/reality/coord.rb