Class: GeoConcerns::Coverage
- Inherits:
-
Object
- Object
- GeoConcerns::Coverage
- Defined in:
- app/values/geo_concerns/coverage.rb
Defined Under Namespace
Classes: InvalidGeometryError, ParseError
Instance Attribute Summary collapse
-
#e ⇒ Object
readonly
Returns the value of attribute e.
-
#n ⇒ Object
readonly
Returns the value of attribute n.
-
#s ⇒ Object
readonly
Returns the value of attribute s.
-
#w ⇒ Object
readonly
Returns the value of attribute w.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(n, e, s, w) ⇒ Coverage
constructor
A new instance of Coverage.
- #to_s ⇒ Object
Constructor Details
#initialize(n, e, s, w) ⇒ Coverage
Returns a new instance of Coverage.
23 24 25 26 27 28 29 30 |
# File 'app/values/geo_concerns/coverage.rb', line 23 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 |
Instance Attribute Details
#e ⇒ Object (readonly)
Returns the value of attribute e.
6 7 8 |
# File 'app/values/geo_concerns/coverage.rb', line 6 def e @e end |
#n ⇒ Object (readonly)
Returns the value of attribute n.
6 7 8 |
# File 'app/values/geo_concerns/coverage.rb', line 6 def n @n end |
#s ⇒ Object (readonly)
Returns the value of attribute s.
6 7 8 |
# File 'app/values/geo_concerns/coverage.rb', line 6 def s @s end |
#w ⇒ Object (readonly)
Returns the value of attribute w.
6 7 8 |
# File 'app/values/geo_concerns/coverage.rb', line 6 def w @w end |
Class Method Details
.parse(str) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'app/values/geo_concerns/coverage.rb', line 8 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 |
.parse_coordinate(str, regex) ⇒ Object
19 20 21 |
# File 'app/values/geo_concerns/coverage.rb', line 19 def self.parse_coordinate(str, regex) Regexp.last_match(1).to_f if str =~ regex end |
Instance Method Details
#to_s ⇒ Object
32 33 34 |
# File 'app/values/geo_concerns/coverage.rb', line 32 def to_s "northlimit=#{n}; eastlimit=#{e}; southlimit=#{s}; westlimit=#{w}; units=degrees; projection=EPSG:4326" end |