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
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
@latitude, @longitude, = arguments
end
end
|
Instance Attribute Details
Returns the value of attribute latitude.
87
88
89
|
# File 'lib/groonga/geo-point.rb', line 87
def latitude
@latitude
end
|
#longitude ⇒ Object
Returns the value of attribute longitude.
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)
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
|
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
|
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
|
129
130
131
|
# File 'lib/groonga/geo-point.rb', line 129
def to_s
"#{latitude}x#{longitude}"
end
|