Class: Groonga::GeoPoint
- Inherits:
-
Object
show all
- Defined in:
- lib/groonga/geo-point.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(geo_point_in_string) ⇒ GeoPoint
#initialize(latitude, longitude) ⇒ GeoPoint
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
@latitude, @longitude, = arguments
end
end
|
Instance Attribute Details
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)
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
|
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
|
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
|
128
129
130
|
# File 'lib/groonga/geo-point.rb', line 128
def to_s
"#{latitude}x#{longitude}"
end
|