Class: GeoConcerns::Coverage

Inherits:
Object
  • Object
show all
Defined in:
app/values/geo_concerns/coverage.rb

Defined Under Namespace

Classes: InvalidGeometryError, ParseError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#eObject (readonly)

Returns the value of attribute e.



6
7
8
# File 'app/values/geo_concerns/coverage.rb', line 6

def e
  @e
end

#nObject (readonly)

Returns the value of attribute n.



6
7
8
# File 'app/values/geo_concerns/coverage.rb', line 6

def n
  @n
end

#sObject (readonly)

Returns the value of attribute s.



6
7
8
# File 'app/values/geo_concerns/coverage.rb', line 6

def s
  @s
end

#wObject (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_sObject



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