Class: Groonga::GeoPoint
- Inherits:
-
Object
- Object
- Groonga::GeoPoint
- Defined in:
- lib/groonga/geo-point.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#latitude ⇒ Object
Returns the value of attribute latitude.
-
#longitude ⇒ Object
Returns the value of attribute longitude.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #degree? ⇒ Boolean
-
#initialize(*arguments) ⇒ GeoPoint
constructor
TODO: write document.
- #inspect ⇒ Object
- #msec? ⇒ Boolean
- #to_degree ⇒ Object
- #to_msec ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(geo_point_in_string) ⇒ GeoPoint #initialize(latitude, longitude) ⇒ GeoPoint
TODO: write document
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/groonga/geo-point.rb', line 90 def initialize(*arguments) if arguments.size == 1 if arguments.first.is_a?(String) geo_point = self.class.parse(arguments.first) else geo_point = arguments.first geo_point = coerce(geo_point) end @latitude = geo_point.latitude @longitude = geo_point.longitude else # TODO: check # of arguments @latitude, @longitude, = arguments end end |
Instance Attribute Details
#latitude ⇒ Object
Returns the value of attribute latitude.
86 87 88 |
# File 'lib/groonga/geo-point.rb', line 86 def latitude @latitude end |
#longitude ⇒ Object
Returns the value of attribute longitude.
86 87 88 |
# File 'lib/groonga/geo-point.rb', line 86 def longitude @longitude end |
Class Method Details
.parse(string) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/groonga/geo-point.rb', line 78 def parse(string) # TODO: validation latitude, longitude = string.split(/[x,]/, 2) new(GeoPointValueConverter.parse(latitude), GeoPointValueConverter.parse(longitude)) end |
Instance Method Details
#==(other) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/groonga/geo-point.rb', line 136 def ==(other) case other when String to_s == otehr when GeoPoint normalized_self = to_msec normalized_other = coerce(other).to_msec [normalized_self.latitude, normalized_self.longitude] == [normalized_other.latitude, normalized_other.longitude] else false end end |
#degree? ⇒ Boolean
106 107 108 109 |
# File 'lib/groonga/geo-point.rb', line 106 def degree? GeoPointValueConverter.degree?(latitude) and GeoPointValueConverter.degree?(longitude) end |
#inspect ⇒ Object
132 133 134 |
# File 'lib/groonga/geo-point.rb', line 132 def inspect "#<#{self.class} #{to_s}>" end |
#msec? ⇒ Boolean
111 112 113 114 |
# File 'lib/groonga/geo-point.rb', line 111 def msec? GeoPointValueConverter.msec?(latitude) and GeoPointValueConverter.msec?(longitude) end |
#to_degree ⇒ Object
116 117 118 119 120 |
# File 'lib/groonga/geo-point.rb', line 116 def to_degree return self if degree? self.class.new(GeoPointValueConverter.to_degree(latitude), GeoPointValueConverter.to_degree(longitude)) end |
#to_msec ⇒ Object
122 123 124 125 126 |
# File 'lib/groonga/geo-point.rb', line 122 def to_msec return self if msec? self.class.new(GeoPointValueConverter.to_msec(latitude), GeoPointValueConverter.to_msec(longitude)) end |
#to_s ⇒ Object
128 129 130 |
# File 'lib/groonga/geo-point.rb', line 128 def to_s "#{latitude}x#{longitude}" end |