equationoftime 4.1.1 → 4.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.autotest +39 -0
- data/.gemtest +0 -0
- data/.minitest.rb +2 -0
- data/.ruby-version +1 -0
- data/.settings/org.eclipse.ltk.core.refactoring.prefs +2 -0
- data/CHANGELOG.rdoc +6 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +44 -3
- data/Guardfile +29 -0
- data/{LICENSE.md → LICENSE.rdoc} +0 -0
- data/Manifest.txt +82 -0
- data/README.rdoc +66 -0
- data/Rakefile +60 -45
- data/equationoftime.gemspec +17 -9
- data/examples/Equation_of_Time.jpg +0 -0
- data/examples/analemma_data_generator.rb +58 -0
- data/examples/check_date_type.rb +60 -0
- data/examples/compare_geoc_long_ra.rb +44 -0
- data/examples/data_table_for_astro_dog.rb +45 -0
- data/examples/earth_rotation.rb +42 -0
- data/examples/eot_methods_list.rb +48 -0
- data/examples/eot_plot.r +57 -0
- data/examples/eot_suntimes.rb +149 -0
- data/examples/equation_of_time.py +186 -0
- data/examples/figure_1.jpg +0 -0
- data/examples/file_converter.rb +31 -0
- data/examples/from_readme.rb +14 -0
- data/examples/from_wiki.rb +46 -0
- data/examples/geo_locator.rb +16 -0
- data/examples/getjd.rb +45 -0
- data/examples/gmst_gast_non_sofa.rb +406 -0
- data/examples/input_suntimes.rb +24 -0
- data/examples/julian_day_formula.rb +29 -0
- data/examples/julian_day_formula.txt +12 -0
- data/examples/my_time_conversion.rb +21 -0
- data/examples/nutation_series.txt +678 -0
- data/examples/nutation_table5_3a.txt +682 -0
- data/examples/ptime.rb +162 -0
- data/examples/suntimes.rb +30 -0
- data/examples/suntimes_test.rb +50 -0
- data/examples/t_sofa.rb +8228 -0
- data/examples/test_celes.rb +51 -0
- data/examples/test_ceot.rb +55 -0
- data/examples/test_poly_eval.rb +32 -0
- data/examples/time_scales.rb +29 -0
- data/examples/times_year.rb +53 -0
- data/examples/usage_example.rb +26 -0
- data/examples/use_angles.rb +222 -0
- data/ext/{ceot/eot.c → eot/ceot.c} +1 -1
- data/ext/{ceot/eot.h → eot/ceot.h} +0 -0
- data/ext/{ceot/ceot.c → eot/eot.c} +2 -2
- data/ext/{ceot → eot}/extconf.rb +1 -1
- data/lib/eot.rb +2 -1
- data/lib/eot/angles.rb +28 -28
- data/lib/eot/constants.rb +2 -0
- data/lib/eot/displays.rb +17 -17
- data/lib/eot/eot.so +0 -0
- data/lib/eot/geo_lat_lng_smt.rb +44 -31
- data/lib/eot/init.rb +20 -19
- data/lib/eot/nutation.rb +1 -1
- data/lib/eot/times.rb +22 -22
- data/lib/eot/utilities.rb +5 -5
- data/lib/eot/version.rb +2 -6
- data/test/aliased_angles_spec.rb +239 -0
- data/test/aliased_displays_spec.rb +105 -0
- data/test/aliased_utilities_spec.rb +36 -0
- data/test/angles_spec.rb +264 -0
- data/test/constants_spec.rb +20 -0
- data/test/displays_spec.rb +110 -0
- data/test/geo_spec.rb +38 -0
- data/test/init_spec.rb +44 -0
- data/test/nutation_spec.rb +37 -0
- data/test/spec_config.rb +8 -0
- data/test/times_spec.rb +133 -0
- data/test/utilities_spec.rb +35 -0
- metadata +109 -115
- data/.gitignore +0 -24
- data/.rvmrc +0 -1
- data/README.md +0 -83
- data/README2.txt +0 -70
- data/wiki.md +0 -43
- data/wiki2.md +0 -4
File without changes
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#include "ruby.h"
|
2
|
-
#include "
|
2
|
+
#include "ceot.h"
|
3
3
|
|
4
4
|
#ifndef DBL2NUM
|
5
5
|
# define DBL2NUM(dbl) rb_float_new(dbl)
|
@@ -39,7 +39,7 @@ VALUE func_cosZ(VALUE klass, VALUE vz) {
|
|
39
39
|
|
40
40
|
VALUE cEot;
|
41
41
|
void
|
42
|
-
|
42
|
+
Init_eot(void) {
|
43
43
|
|
44
44
|
VALUE cEot = rb_define_class("Eot", rb_cObject);
|
45
45
|
id_status = rb_intern("@status");
|
data/ext/{ceot → eot}/extconf.rb
RENAMED
data/lib/eot.rb
CHANGED
data/lib/eot/angles.rb
CHANGED
@@ -4,7 +4,7 @@ require 'celes'
|
|
4
4
|
|
5
5
|
class Eot
|
6
6
|
include Math
|
7
|
-
# From angles.rb
|
7
|
+
# From angles.rb:
|
8
8
|
# Apparent solar longitude = true longitude - aberation
|
9
9
|
def al_Sun()
|
10
10
|
#Celes.anp(tl_Sun() - 0.00569 * D2R - 0.00478 * D2R * sin(omega()))
|
@@ -13,7 +13,7 @@ class Eot
|
|
13
13
|
alias_method :apparent_longitude, :al_Sun
|
14
14
|
alias_method :alsun, :al_Sun
|
15
15
|
|
16
|
-
# From angles.rb
|
16
|
+
# From angles.rb:
|
17
17
|
# delta epsilon
|
18
18
|
# component of equation of equinox
|
19
19
|
def angle_delta_epsilon()
|
@@ -21,7 +21,7 @@ class Eot
|
|
21
21
|
end
|
22
22
|
alias_method :delta_epsilon, :angle_delta_epsilon
|
23
23
|
|
24
|
-
# From angles.rb
|
24
|
+
# From angles.rb:
|
25
25
|
# one time component to total equation of time
|
26
26
|
def angle_delta_oblique()
|
27
27
|
al(@ma, @ta, Celes.faom03(@ta)) - ra_Sun()
|
@@ -29,7 +29,7 @@ class Eot
|
|
29
29
|
alias_method :delta_t_ecliptic, :angle_delta_oblique
|
30
30
|
alias_method :delta_oblique, :angle_delta_oblique
|
31
31
|
|
32
|
-
# From angles.rb
|
32
|
+
# From angles.rb:
|
33
33
|
# one time component to total equation of time
|
34
34
|
def angle_delta_orbit()
|
35
35
|
@ma - Celes.anp(@ma + eqc( @ma, @ta ))
|
@@ -38,14 +38,14 @@ class Eot
|
|
38
38
|
alias_method :delta_orbit, :angle_delta_orbit
|
39
39
|
|
40
40
|
|
41
|
-
# From angles.rb
|
41
|
+
# From angles.rb:
|
42
42
|
# component of equation of equinox
|
43
43
|
def angle_delta_psi()
|
44
44
|
Celes.nut06a(@ajd, 0)[ 0 ]
|
45
45
|
end
|
46
46
|
alias_method :delta_psi, :angle_delta_psi
|
47
47
|
|
48
|
-
# From angles.rb
|
48
|
+
# From angles.rb:
|
49
49
|
# total equation of time
|
50
50
|
def angle_equation_of_time()
|
51
51
|
#~ @ma = ma_Sun()
|
@@ -53,7 +53,7 @@ class Eot
|
|
53
53
|
end
|
54
54
|
alias_method :eot, :angle_equation_of_time
|
55
55
|
|
56
|
-
# From angles.rb
|
56
|
+
# From angles.rb:
|
57
57
|
# equation of centre
|
58
58
|
# added to mean anomaly to get true anomaly.
|
59
59
|
def center()
|
@@ -75,7 +75,7 @@ class Eot
|
|
75
75
|
end
|
76
76
|
alias_method :equation_of_center, :center
|
77
77
|
|
78
|
-
# From angles.rb
|
78
|
+
# From angles.rb:
|
79
79
|
# cosine apparent longitude
|
80
80
|
# could be useful when dividing
|
81
81
|
def cosine_al_Sun()
|
@@ -84,7 +84,7 @@ class Eot
|
|
84
84
|
alias_method :cosine_apparent_longitude, :cosine_al_Sun
|
85
85
|
alias_method :cosalsun, :cosine_al_Sun
|
86
86
|
|
87
|
-
# From angles.rb
|
87
|
+
# From angles.rb:
|
88
88
|
# cosine true longitude
|
89
89
|
# used in solar right ascension
|
90
90
|
def cosine_tl_Sun()
|
@@ -92,7 +92,7 @@ class Eot
|
|
92
92
|
end
|
93
93
|
alias_method :cosine_true_longitude, :cosine_tl_Sun
|
94
94
|
|
95
|
-
# From angles.rb
|
95
|
+
# From angles.rb:
|
96
96
|
# cosine true obliquity
|
97
97
|
# used in solar right ascension and equation of equinox
|
98
98
|
def cosine_to_Earth()
|
@@ -100,7 +100,7 @@ class Eot
|
|
100
100
|
end
|
101
101
|
alias_method :cosine_true_obliquity, :cosine_to_Earth
|
102
102
|
|
103
|
-
# From angles.rb
|
103
|
+
# From angles.rb:
|
104
104
|
# solar declination
|
105
105
|
def dec_Sun()
|
106
106
|
asin( sin(Celes.nut06a(@ajd, 0)[ 1 ] + Celes.obl06(@ajd, 0)) *
|
@@ -109,7 +109,7 @@ class Eot
|
|
109
109
|
alias_method :declination, :dec_Sun
|
110
110
|
|
111
111
|
|
112
|
-
# From angles.rb
|
112
|
+
# From angles.rb:
|
113
113
|
# eccentricity of elliptical Earth orbit around Sun
|
114
114
|
# Horners' calculation method
|
115
115
|
def eccentricity_Earth()
|
@@ -118,7 +118,7 @@ class Eot
|
|
118
118
|
end
|
119
119
|
alias_method :eccentricity_earth_orbit, :eccentricity_Earth
|
120
120
|
|
121
|
-
# From angles.rb
|
121
|
+
# From angles.rb:
|
122
122
|
# equation of equinox
|
123
123
|
# used for true longitude of Aries
|
124
124
|
# Depricated by Celes.gst06a()
|
@@ -127,7 +127,7 @@ class Eot
|
|
127
127
|
end
|
128
128
|
|
129
129
|
|
130
|
-
# From angles.rb
|
130
|
+
# From angles.rb:
|
131
131
|
# angle geometric mean longitude
|
132
132
|
# needed to get true longitude for low accuracy.
|
133
133
|
def gml_Sun()
|
@@ -138,7 +138,7 @@ class Eot
|
|
138
138
|
end
|
139
139
|
alias_method :geometric_mean_longitude, :gml_Sun
|
140
140
|
|
141
|
-
# From angles.rb
|
141
|
+
# From angles.rb:
|
142
142
|
# horizon angle for provided geo coordinates
|
143
143
|
# used for angles from transit to horizons
|
144
144
|
def ha_Sun()
|
@@ -151,7 +151,7 @@ class Eot
|
|
151
151
|
end
|
152
152
|
alias_method :horizon_angle, :ha_Sun
|
153
153
|
|
154
|
-
# From angles.rb
|
154
|
+
# From angles.rb:
|
155
155
|
# angle of Suns' mean anomaly
|
156
156
|
# calculated in nutation.rb via celes function
|
157
157
|
# sets ta attribute for the rest the methods needing it.
|
@@ -164,7 +164,7 @@ class Eot
|
|
164
164
|
end
|
165
165
|
alias_method :mean_anomaly, :ma_Sun
|
166
166
|
|
167
|
-
# From angles.rb
|
167
|
+
# From angles.rb:
|
168
168
|
# Mean equinox point where right ascension is measured from as zero hours.
|
169
169
|
# # see http://www.iausofa.org/publications/aas04.pdf
|
170
170
|
def ml_Aries()
|
@@ -188,7 +188,7 @@ class Eot
|
|
188
188
|
end
|
189
189
|
alias_method :mean_longitude_aries, :ml_Aries
|
190
190
|
|
191
|
-
# From angles.rb
|
191
|
+
# From angles.rb:
|
192
192
|
# mean obliquity of Earth
|
193
193
|
def mo_Earth()
|
194
194
|
# [ -0.0000000434, -0.000000576, 0.00200340,
|
@@ -198,7 +198,7 @@ class Eot
|
|
198
198
|
alias_method :mean_obliquity_of_ecliptic, :mo_Earth
|
199
199
|
alias_method :mean_obliquity, :mo_Earth
|
200
200
|
|
201
|
-
# From angles.rb
|
201
|
+
# From angles.rb:
|
202
202
|
# omega is a component of nutation and used
|
203
203
|
# in apparent longitude
|
204
204
|
# omega is the longitude of the mean ascending node of the lunar orbit
|
@@ -208,7 +208,7 @@ class Eot
|
|
208
208
|
Celes.faom03(@ta)
|
209
209
|
end
|
210
210
|
|
211
|
-
# From angles.rb
|
211
|
+
# From angles.rb:
|
212
212
|
# solar right ascension
|
213
213
|
def ra_Sun()
|
214
214
|
y0 = sin( al(@ma, @ta, Celes.faom03(@ta)) ) * cos( Celes.nut06a(@ajd, 0)[ 1 ] +
|
@@ -217,7 +217,7 @@ class Eot
|
|
217
217
|
end
|
218
218
|
alias_method :right_ascension, :ra_Sun
|
219
219
|
|
220
|
-
# From angles.rb
|
220
|
+
# From angles.rb:
|
221
221
|
# sine apparent longitude
|
222
222
|
# used in solar declination
|
223
223
|
def sine_al_Sun()
|
@@ -225,7 +225,7 @@ class Eot
|
|
225
225
|
end
|
226
226
|
alias_method :sine_apparent_longitude, :sine_al_Sun
|
227
227
|
|
228
|
-
# From angles.rb
|
228
|
+
# From angles.rb:
|
229
229
|
# sine true longitude
|
230
230
|
# used in solar right ascension
|
231
231
|
def sine_tl_Sun()
|
@@ -233,14 +233,14 @@ class Eot
|
|
233
233
|
end
|
234
234
|
alias_method :sine_true_longitude, :sine_tl_Sun
|
235
235
|
|
236
|
-
# From angles.rb
|
236
|
+
# From angles.rb:
|
237
237
|
# sine true obliquity angle of Earth
|
238
238
|
# used in solar declination
|
239
239
|
def sine_to_Earth()
|
240
240
|
sin(Celes.nut06a(@ajd, 0)[ 1 ] + Celes.obl06(@ajd, 0))
|
241
241
|
end
|
242
242
|
|
243
|
-
# From angles.rb
|
243
|
+
# From angles.rb:
|
244
244
|
# angle true anomaly
|
245
245
|
# used in equation of time
|
246
246
|
def ta_Sun()
|
@@ -248,7 +248,7 @@ class Eot
|
|
248
248
|
end
|
249
249
|
alias_method :true_anomaly, :ta_Sun
|
250
250
|
|
251
|
-
# From angles.rb
|
251
|
+
# From angles.rb:
|
252
252
|
# true longitude of equinox 'first point of aries'
|
253
253
|
# considers nutation
|
254
254
|
def tl_Aries()
|
@@ -259,7 +259,7 @@ class Eot
|
|
259
259
|
end
|
260
260
|
alias_method :true_longitude_aries, :tl_Aries
|
261
261
|
|
262
|
-
# From angles.rb
|
262
|
+
# From angles.rb:
|
263
263
|
# angle of true longitude sun
|
264
264
|
# used in equation of time
|
265
265
|
def tl_Sun()
|
@@ -270,7 +270,7 @@ class Eot
|
|
270
270
|
alias_method :ecliptic_longitude, :tl_Sun
|
271
271
|
alias_method :lambda, :tl_Sun
|
272
272
|
|
273
|
-
# From angles.rb
|
273
|
+
# From angles.rb:
|
274
274
|
# true obliquity considers nutation
|
275
275
|
def to_Earth()
|
276
276
|
Celes.nut06a(@ajd, 0)[ 1 ] + Celes.obl06(@ajd, 0)
|
@@ -283,7 +283,7 @@ end
|
|
283
283
|
|
284
284
|
if __FILE__ == $PROGRAM_NAME
|
285
285
|
|
286
|
-
spec = File.expand_path('../../../
|
286
|
+
spec = File.expand_path('../../../test/', __FILE__)
|
287
287
|
$LOAD_PATH.unshift(spec) unless $LOAD_PATH.include?(spec)
|
288
288
|
require 'angles_spec'
|
289
289
|
require 'aliased_angles_spec'
|
data/lib/eot/constants.rb
CHANGED
data/lib/eot/displays.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
class Eot
|
4
4
|
|
5
|
-
# From displays.rb
|
5
|
+
# From displays.rb
|
6
6
|
# String formatter for d:m:s display
|
7
7
|
def degrees_to_s( radians = 0.0 )
|
8
8
|
radians.nil? ? radians = 0.0 : radians
|
@@ -41,7 +41,7 @@ class Eot
|
|
41
41
|
"%3.3d" % absolute_milli_seconds_integer
|
42
42
|
end
|
43
43
|
|
44
|
-
# From displays.rb
|
44
|
+
# From displays.rb
|
45
45
|
# String formatter for + and - time
|
46
46
|
def show_minutes(min = 0.0)
|
47
47
|
min.nil? ? min = 0.0 : min
|
@@ -55,20 +55,20 @@ class Eot
|
|
55
55
|
time.strftime("#{sign}%M:%S.%3N")
|
56
56
|
end
|
57
57
|
|
58
|
-
# From displays.rb
|
58
|
+
# From displays.rb
|
59
59
|
# String for time now
|
60
60
|
def show_now(now = now(Time.now.utc))
|
61
61
|
show_minutes(now)
|
62
62
|
end
|
63
63
|
|
64
|
-
# From displays.rb
|
64
|
+
# From displays.rb
|
65
65
|
# String format of apparent longitude
|
66
66
|
def string_al_Sun()
|
67
67
|
degrees_to_s( al_Sun() )
|
68
68
|
end
|
69
69
|
alias_method :apparent_longitude_string, :string_al_Sun
|
70
70
|
|
71
|
-
# From displays.rb
|
71
|
+
# From displays.rb
|
72
72
|
# String formatter for fraction of Julian day number
|
73
73
|
def string_day_fraction_to_time( jpd_time = 0.0 )
|
74
74
|
jpd_time.nil? ? jpd_time = 0.0 : jpd_time
|
@@ -84,32 +84,32 @@ class Eot
|
|
84
84
|
end
|
85
85
|
alias_method :julian_period_day_fraction_to_time, :string_day_fraction_to_time
|
86
86
|
|
87
|
-
# From displays.rb
|
87
|
+
# From displays.rb
|
88
88
|
# String format of declination
|
89
89
|
def string_dec_Sun()
|
90
90
|
degrees_to_s( dec_Sun() )
|
91
91
|
end
|
92
92
|
alias_method :declination_string, :string_dec_Sun
|
93
93
|
|
94
|
-
# From displays.rb
|
94
|
+
# From displays.rb
|
95
95
|
# String format for delta oblique
|
96
96
|
def string_delta_oblique()
|
97
97
|
show_minutes(delta_oblique())
|
98
98
|
end
|
99
99
|
|
100
|
-
# From displays.rb
|
100
|
+
# From displays.rb
|
101
101
|
# String format for delta orbit
|
102
102
|
def string_delta_orbit()
|
103
103
|
show_minutes(delta_orbit())
|
104
104
|
end
|
105
105
|
|
106
|
-
# From displays.rb
|
106
|
+
# From displays.rb
|
107
107
|
# String format for centre
|
108
108
|
def string_eqc()
|
109
109
|
degrees_to_s( center())
|
110
110
|
end
|
111
111
|
|
112
|
-
# From displays.rb
|
112
|
+
# From displays.rb
|
113
113
|
# Equation of time output for minutes and seconds
|
114
114
|
def string_eot()
|
115
115
|
eot = time_eot()
|
@@ -130,7 +130,7 @@ class Eot
|
|
130
130
|
end
|
131
131
|
alias_method :display_equation_of_time, :string_eot
|
132
132
|
|
133
|
-
# From displays.rb
|
133
|
+
# From displays.rb
|
134
134
|
# String format conversion of jd to date
|
135
135
|
def string_jd_to_date( jd = DJ00 )
|
136
136
|
jd = check_jd_zero( jd )
|
@@ -138,28 +138,28 @@ class Eot
|
|
138
138
|
end
|
139
139
|
alias_method :jd_to_date_string, :string_jd_to_date
|
140
140
|
|
141
|
-
# From displays.rb
|
141
|
+
# From displays.rb
|
142
142
|
# String format of mean anomaly
|
143
143
|
def string_ma_Sun()
|
144
144
|
degrees_to_s( @ma )
|
145
145
|
end
|
146
146
|
alias_method :mean_anomaly_string, :string_ma_Sun
|
147
147
|
|
148
|
-
# From displays.rb
|
148
|
+
# From displays.rb
|
149
149
|
# String format of right ascension
|
150
150
|
def string_ra_Sun()
|
151
151
|
degrees_to_s( ra_Sun() )
|
152
152
|
end
|
153
153
|
alias_method :right_ascension_string, :string_ra_Sun
|
154
154
|
|
155
|
-
# From displays.rb
|
155
|
+
# From displays.rb
|
156
156
|
# String format of true anomaly
|
157
157
|
def string_ta_Sun( )
|
158
158
|
degrees_to_s( ta_Sun() )
|
159
159
|
end
|
160
160
|
alias_method :true_anomaly_string, :string_ta_Sun
|
161
161
|
|
162
|
-
# From displays.rb
|
162
|
+
# From displays.rb
|
163
163
|
# String formatter for h:m:s display
|
164
164
|
def string_time( dt = DT2000 )
|
165
165
|
dt = check_t_zero( dt )
|
@@ -190,14 +190,14 @@ class Eot
|
|
190
190
|
end
|
191
191
|
alias_method :display_time_string, :string_time
|
192
192
|
|
193
|
-
# From displays.rb
|
193
|
+
# From displays.rb
|
194
194
|
# String format of true longitude
|
195
195
|
def string_tl_Sun()
|
196
196
|
degrees_to_s( tl_Sun() )
|
197
197
|
end
|
198
198
|
alias_method :true_longitude_string, :string_tl_Sun
|
199
199
|
|
200
|
-
# From displays.rb
|
200
|
+
# From displays.rb
|
201
201
|
# String format of true obliquity
|
202
202
|
def string_to_Earth()
|
203
203
|
degrees_to_s( to_Earth() )
|
data/lib/eot/eot.so
ADDED
Binary file
|
data/lib/eot/geo_lat_lng_smt.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# geo_lat_lng_smt.rb
|
2
2
|
|
3
|
-
require 'multi_xml'
|
3
|
+
# require 'multi_xml'
|
4
4
|
require 'rest-client'
|
5
|
+
require 'json'
|
5
6
|
|
6
7
|
# class for location lookup
|
7
8
|
# in geo_lat_lng_smt.rb
|
@@ -25,46 +26,40 @@ class GeoLatLng
|
|
25
26
|
# Longitude returned
|
26
27
|
attr_accessor :lng
|
27
28
|
|
28
|
-
# Base Google URL
|
29
|
-
attr_reader :base
|
30
|
-
|
31
29
|
# Instance variables
|
32
30
|
def initialize
|
33
31
|
|
34
|
-
@base = "http://maps.googleapis.com/maps/api/geocode/
|
32
|
+
@base = "http://maps.googleapis.com/maps/api/geocode/json?address="
|
33
|
+
# @base = "http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address="
|
35
34
|
@default_us = "3333 Coyote Hill Road, Palo Alto, CA, 94304, USA"#do you copy? :D
|
36
35
|
@default_int = "Blackheath Ave, London SE10 8XJ, UK"
|
37
36
|
@lat = 0.0
|
38
37
|
@lng = 0.0
|
39
|
-
MultiXml.parser = :rexml#:libxml#:ox # :nokogiri
|
40
|
-
@addr
|
38
|
+
# MultiXml.parser = :rexml#:libxml#:ox # :nokogiri
|
39
|
+
@addr = @default_int
|
41
40
|
|
42
41
|
end
|
43
42
|
|
44
43
|
# set address
|
45
|
-
def addr=(addr = @default_int)
|
46
|
-
|
47
|
-
end
|
44
|
+
#def addr=(addr = @default_int)
|
45
|
+
# @addr = addr
|
46
|
+
#end
|
48
47
|
|
49
48
|
# coordinates lookup
|
50
|
-
def get_coordinates_from_address
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
status = parsed_res[ "GeocodeResponse" ][ "status" ]
|
49
|
+
def get_coordinates_from_address
|
50
|
+
addr = URI.escape( @base + @addr )
|
51
|
+
resrc = RestClient.get( addr )
|
52
|
+
parsed_resrc = JSON.parse(resrc)#MultiXml.parse( res )
|
53
|
+
#~ result = parsed_res[ "GeocodeResponse" ][ "result" ]
|
54
|
+
results = parsed_resrc["results"]
|
55
|
+
#~ status = parsed_res#[ "GeocodeResponse" ][ "status" ]
|
56
|
+
status = parsed_resrc[ "status" ]
|
59
57
|
if status != "OK"
|
60
|
-
@default_int
|
61
|
-
else
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
@lat = parsed_res[ "GeocodeResponse" ][ "result" ][ "geometry" ][ "location" ][ "lat" ].to_f
|
66
|
-
@lng = parsed_res[ "GeocodeResponse" ][ "result" ][ "geometry" ][ "location" ][ "lng" ].to_f
|
67
|
-
end
|
58
|
+
@addr = @default_int
|
59
|
+
else
|
60
|
+
@lat = results[0]["geometry"]["location"][ "lat" ].to_f
|
61
|
+
@lng = results[0]["geometry"]["location"][ "lng" ].to_f
|
62
|
+
|
68
63
|
end
|
69
64
|
|
70
65
|
end
|
@@ -72,10 +67,28 @@ class GeoLatLng
|
|
72
67
|
end
|
73
68
|
|
74
69
|
if __FILE__ == $PROGRAM_NAME
|
75
|
-
|
76
|
-
|
77
|
-
$LOAD_PATH.unshift(
|
78
|
-
|
70
|
+
|
71
|
+
lib = File.expand_path('../../../lib', __FILE__)
|
72
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
73
|
+
|
74
|
+
require 'eot'
|
75
|
+
eot = Eot.new
|
76
|
+
p eot.addr
|
77
|
+
p eot.latitude
|
78
|
+
p eot.longitude
|
79
|
+
geo = GeoLatLng.new()
|
80
|
+
p geo.addr
|
81
|
+
p geo.lat
|
82
|
+
p geo.lng
|
83
|
+
geo.get_coordinates_from_address()
|
84
|
+
p geo.lat
|
85
|
+
p geo.lng
|
86
|
+
#~ gem 'minitest'
|
87
|
+
#~ require 'minitest/autorun'
|
88
|
+
#~ spec = File.expand_path('../../../test/', __FILE__)
|
89
|
+
#~ $LOAD_PATH.unshift(spec) unless $LOAD_PATH.include?(spec)
|
90
|
+
#~ require 'geo_spec'
|
91
|
+
system 'rake test'
|
79
92
|
|
80
93
|
end
|
81
94
|
|