Sha256: bd4c41fdbd69c93c78451916af72a8e528c0d008f13d5032ec2805315b58fbd1

Contents?: true

Size: 1015 Bytes

Versions: 18

Compression:

Stored size: 1015 Bytes

Contents

module GeoConcerns
  class Coverage
    class ParseError < StandardError; end
    class InvalidGeometryError < StandardError; end

    attr_reader :n, :e, :s, :w

    def self.parse(str)
      n = parse_coordinate(str, /northlimit=([\.\d\-]+);/)
      e = parse_coordinate(str, /eastlimit=([\.\d\-]+);/)
      s = parse_coordinate(str, /southlimit=([\.\d\-]+);/)
      w = parse_coordinate(str, /westlimit=([\.\d\-]+);/)
      raise ParseError, str if n.nil? || e.nil? || s.nil? || w.nil?
      new(n, e, s, w)
    rescue
      nil
    end

    def self.parse_coordinate(str, regex)
      Regexp.last_match(1).to_f if str =~ regex
    end

    def initialize(n, e, s, w)
      raise InvalidGeometryError, "n=#{n} < s=#{s}" if n.to_f < s.to_f
      raise InvalidGeometryError, "e=#{e} < w=#{w}" if e.to_f < w.to_f
      @n = n
      @e = e
      @s = s
      @w = w
    end

    def to_s
      "northlimit=#{n}; eastlimit=#{e}; southlimit=#{s}; westlimit=#{w}; units=degrees; projection=EPSG:4326"
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
geo_concerns-0.3.4 app/values/geo_concerns/coverage.rb
geo_concerns-0.3.3 app/values/geo_concerns/coverage.rb
geo_concerns-0.3.2 app/values/geo_concerns/coverage.rb
geo_concerns-0.3.1 app/values/geo_concerns/coverage.rb
geo_concerns-0.3.0 app/values/geo_concerns/coverage.rb
geo_concerns-0.2.0 app/values/geo_concerns/coverage.rb
geo_concerns-0.1.1 app/values/geo_concerns/coverage.rb
geo_concerns-0.1.0 app/values/geo_concerns/coverage.rb
geo_concerns-0.0.10 app/values/geo_concerns/coverage.rb
geo_concerns-0.0.9 app/values/geo_concerns/coverage.rb
geo_concerns-0.0.8 app/values/geo_concerns/coverage.rb
geo_concerns-0.0.7 app/values/geo_concerns/coverage.rb
geo_concerns-0.0.6 app/values/geo_concerns/coverage.rb
geo_concerns-0.0.5 app/values/geo_concerns/coverage.rb
geo_concerns-0.0.4 app/values/geo_concerns/coverage.rb
geo_concerns-0.0.3 app/values/geo_concerns/coverage.rb
geo_concerns-0.0.2 app/values/geo_concerns/coverage.rb
geo_concerns-0.0.1 app/values/geo_concerns/coverage.rb