Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/string_conversions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#coordinatesObject

Returns the value of attribute coordinates.



3
4
5
# File 'lib/string_conversions.rb', line 3

def coordinates
  @coordinates
end

Instance Method Details

#is_gridref?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/string_conversions.rb', line 5

def is_gridref?
  !!(self.upcase =~ /^(H(P|T|U|Y|Z)|N(A|B|C|D|F|G|H|J|K|L|M|N|O|R|S|T|U|W|X|Y|Z)|OV|S(C|D|E|G|H|J|K|M|N|O|P|R|S|T|U|W|X|Y|Z)|T(A|F|G|L|M|Q|R|V)){1}\d{4}(NE|NW|SE|SW)?$|((H(P|T|U|Y|Z)|N(A|B|C|D|F|G|H|J|K|L|M|N|O|R|S|T|U|W|X|Y|Z)|OV|S(C|D|E|G|H|J|K|M|N|O|P|R|S|T|U|W|X|Y|Z)|T(A|F|G|L|M|Q|R|V)){1}(\d{4}|\d{6}|\d{8}|\d{10}))$/)
end

#is_latlng?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/string_conversions.rb', line 9

def is_latlng?
  !!coordinates
end

#to_latlng(options = {}) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/string_conversions.rb', line 21

def to_latlng(options = {})
  if is_gridref?
    GridRef.new(self, options).to_latlng
  else
    self.coordinates
  end
end

#to_wgs84(options = {}) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/string_conversions.rb', line 29

def to_wgs84(options = {})
  if is_gridref?
    GridRef.new(self, options.merge(:datum => :wgs84)).to_latlng
  else
    self.coordinates
  end
end