Class: Groonga::GeoPoint
- Inherits:
-
Object
- Object
- Groonga::GeoPoint
- Defined in:
- lib/groonga/geo-point.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#latitude ⇒ Object
緯度の値を返す。.
-
#longitude ⇒ Object
経度の値を返す。.
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
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/groonga/geo-point.rb', line 91 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
緯度の値を返す。
87 88 89 |
# File 'lib/groonga/geo-point.rb', line 87 def latitude @latitude end |
#longitude ⇒ Object
経度の値を返す。
87 88 89 |
# File 'lib/groonga/geo-point.rb', line 87 def longitude @longitude end |
Class Method Details
.parse(string) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/groonga/geo-point.rb', line 79 def parse(string) # TODO: validation latitude, longitude = string.split(/[x,]/, 2) new(GeoPointValueConverter.parse(latitude), GeoPointValueConverter.parse(longitude)) end |
Instance Method Details
#==(other) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/groonga/geo-point.rb', line 137 def ==(other) case other when String to_s == other 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
107 108 109 110 |
# File 'lib/groonga/geo-point.rb', line 107 def degree? GeoPointValueConverter.degree?(latitude) and GeoPointValueConverter.degree?(longitude) end |
#inspect ⇒ Object
133 134 135 |
# File 'lib/groonga/geo-point.rb', line 133 def inspect "#<#{self.class} #{to_s}>" end |
#msec? ⇒ Boolean
112 113 114 115 |
# File 'lib/groonga/geo-point.rb', line 112 def msec? GeoPointValueConverter.msec?(latitude) and GeoPointValueConverter.msec?(longitude) end |
#to_degree ⇒ Object
117 118 119 120 121 |
# File 'lib/groonga/geo-point.rb', line 117 def to_degree return self if degree? self.class.new(GeoPointValueConverter.to_degree(latitude), GeoPointValueConverter.to_degree(longitude)) end |
#to_msec ⇒ Object
123 124 125 126 127 |
# File 'lib/groonga/geo-point.rb', line 123 def to_msec return self if msec? self.class.new(GeoPointValueConverter.to_msec(latitude), GeoPointValueConverter.to_msec(longitude)) end |
#to_s ⇒ Object
129 130 131 |
# File 'lib/groonga/geo-point.rb', line 129 def to_s "#{latitude}x#{longitude}" end |