gooby 1.2.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +133 -341
- data/config/ballantyne.yaml +11 -0
- data/config/big_sur_marathon.yaml +11 -0
- data/config/crowders_mtn_hike.yaml +11 -0
- data/config/davidson1.yaml +16 -0
- data/config/gooby_config.yaml +28 -135
- data/cucumber.yml +1 -0
- data/features/build_gem.feature +88 -0
- data/features/gooby.feature +300 -0
- data/features/install.feature +78 -0
- data/features/steps/gooby_steps.rb +245 -0
- data/features/support/env.rb +4 -0
- data/lib/gooby.rb +24 -30
- data/lib/gooby_activity.rb +63 -0
- data/lib/gooby_base_object.rb +46 -0
- data/lib/gooby_base_sax_parser.rb +95 -0
- data/lib/gooby_configuration.rb +33 -115
- data/lib/gooby_counter_hash.rb +28 -87
- data/lib/gooby_dttm.rb +88 -66
- data/lib/gooby_environment.rb +48 -0
- data/lib/gooby_garmin_tcx_parser.rb +92 -0
- data/lib/gooby_google_kml_generator.rb +168 -0
- data/lib/gooby_google_map_generator.rb +284 -349
- data/lib/gooby_gpx_parser.rb +97 -0
- data/lib/gooby_help_producer.rb +40 -0
- data/lib/gooby_introspection.rb +25 -0
- data/lib/gooby_io.rb +30 -0
- data/lib/gooby_lap.rb +27 -18
- data/lib/gooby_process.rb +281 -0
- data/lib/gooby_sax_path_parser.rb +43 -0
- data/lib/gooby_tcx_extractor.rb +71 -0
- data/lib/gooby_track_log_parser.rb +114 -0
- data/lib/gooby_trackpoint.rb +276 -0
- data/lib/gooby_xml_object.rb +40 -0
- data/{img/gicons → out/images}/blank.png +0 -0
- data/{img/gicons → out/images}/dd-end.png +0 -0
- data/{img/gicons → out/images}/dd-start.png +0 -0
- data/{img/gicons → out/images}/marker.png +0 -0
- data/{img/gicons → out/images}/marker0.png +0 -0
- data/{img/gicons → out/images}/marker00.png +0 -0
- data/{img/gicons → out/images}/marker01.png +0 -0
- data/{img/gicons → out/images}/marker02.png +0 -0
- data/{img/gicons → out/images}/marker03.png +0 -0
- data/{img/gicons → out/images}/marker04.png +0 -0
- data/{img/gicons → out/images}/marker05.png +0 -0
- data/{img/gicons → out/images}/marker06.png +0 -0
- data/{img/gicons → out/images}/marker07.png +0 -0
- data/{img/gicons → out/images}/marker08.png +0 -0
- data/{img/gicons → out/images}/marker09.png +0 -0
- data/{img/gicons → out/images}/marker1.png +0 -0
- data/{img/gicons → out/images}/marker10.png +0 -0
- data/{img/gicons → out/images}/marker11.png +0 -0
- data/{img/gicons → out/images}/marker12.png +0 -0
- data/{img/gicons → out/images}/marker13.png +0 -0
- data/{img/gicons → out/images}/marker14.png +0 -0
- data/{img/gicons → out/images}/marker15.png +0 -0
- data/{img/gicons → out/images}/marker16.png +0 -0
- data/{img/gicons → out/images}/marker17.png +0 -0
- data/{img/gicons → out/images}/marker18.png +0 -0
- data/{img/gicons → out/images}/marker19.png +0 -0
- data/{img/gicons → out/images}/marker2.png +0 -0
- data/{img/gicons → out/images}/marker20.png +0 -0
- data/{img/gicons → out/images}/marker21.png +0 -0
- data/{img/gicons → out/images}/marker22.png +0 -0
- data/{img/gicons → out/images}/marker23.png +0 -0
- data/{img/gicons → out/images}/marker24.png +0 -0
- data/{img/gicons → out/images}/marker25.png +0 -0
- data/{img/gicons → out/images}/marker26.png +0 -0
- data/{img/gicons → out/images}/marker27.png +0 -0
- data/{img/gicons → out/images}/marker28.png +0 -0
- data/{img/gicons → out/images}/marker29.png +0 -0
- data/{img/gicons → out/images}/marker3.png +0 -0
- data/{img/gicons → out/images}/marker30.png +0 -0
- data/{img/gicons → out/images}/marker31.png +0 -0
- data/{img/gicons → out/images}/marker32.png +0 -0
- data/{img/gicons → out/images}/marker33.png +0 -0
- data/{img/gicons → out/images}/marker34.png +0 -0
- data/{img/gicons → out/images}/marker35.png +0 -0
- data/{img/gicons → out/images}/marker36.png +0 -0
- data/{img/gicons → out/images}/marker37.png +0 -0
- data/{img/gicons → out/images}/marker38.png +0 -0
- data/{img/gicons → out/images}/marker39.png +0 -0
- data/{img/gicons → out/images}/marker4.png +0 -0
- data/{img/gicons → out/images}/marker40.png +0 -0
- data/{img/gicons → out/images}/marker41.png +0 -0
- data/{img/gicons → out/images}/marker42.png +0 -0
- data/{img/gicons → out/images}/marker43.png +0 -0
- data/{img/gicons → out/images}/marker44.png +0 -0
- data/{img/gicons → out/images}/marker45.png +0 -0
- data/{img/gicons → out/images}/marker46.png +0 -0
- data/{img/gicons → out/images}/marker47.png +0 -0
- data/{img/gicons → out/images}/marker48.png +0 -0
- data/{img/gicons → out/images}/marker49.png +0 -0
- data/{img/gicons → out/images}/marker5.png +0 -0
- data/{img/gicons → out/images}/marker50.png +0 -0
- data/{img/gicons → out/images}/marker51.png +0 -0
- data/{img/gicons → out/images}/marker52.png +0 -0
- data/{img/gicons → out/images}/marker53.png +0 -0
- data/{img/gicons → out/images}/marker54.png +0 -0
- data/{img/gicons → out/images}/marker55.png +0 -0
- data/{img/gicons → out/images}/marker56.png +0 -0
- data/{img/gicons → out/images}/marker57.png +0 -0
- data/{img/gicons → out/images}/marker58.png +0 -0
- data/{img/gicons → out/images}/marker59.png +0 -0
- data/{img/gicons → out/images}/marker6.png +0 -0
- data/{img/gicons → out/images}/marker60.png +0 -0
- data/{img/gicons → out/images}/marker61.png +0 -0
- data/{img/gicons → out/images}/marker62.png +0 -0
- data/{img/gicons → out/images}/marker63.png +0 -0
- data/{img/gicons → out/images}/marker64.png +0 -0
- data/{img/gicons → out/images}/marker65.png +0 -0
- data/{img/gicons → out/images}/marker66.png +0 -0
- data/{img/gicons → out/images}/marker67.png +0 -0
- data/{img/gicons → out/images}/marker68.png +0 -0
- data/{img/gicons → out/images}/marker69.png +0 -0
- data/{img/gicons → out/images}/marker7.png +0 -0
- data/{img/gicons → out/images}/marker70.png +0 -0
- data/{img/gicons → out/images}/marker71.png +0 -0
- data/{img/gicons → out/images}/marker72.png +0 -0
- data/{img/gicons → out/images}/marker73.png +0 -0
- data/{img/gicons → out/images}/marker74.png +0 -0
- data/{img/gicons → out/images}/marker75.png +0 -0
- data/{img/gicons → out/images}/marker76.png +0 -0
- data/{img/gicons → out/images}/marker77.png +0 -0
- data/{img/gicons → out/images}/marker78.png +0 -0
- data/{img/gicons → out/images}/marker79.png +0 -0
- data/{img/gicons → out/images}/marker8.png +0 -0
- data/{img/gicons → out/images}/marker80.png +0 -0
- data/{img/gicons → out/images}/marker81.png +0 -0
- data/{img/gicons → out/images}/marker82.png +0 -0
- data/{img/gicons → out/images}/marker83.png +0 -0
- data/{img/gicons → out/images}/marker84.png +0 -0
- data/{img/gicons → out/images}/marker85.png +0 -0
- data/{img/gicons → out/images}/marker86.png +0 -0
- data/{img/gicons → out/images}/marker87.png +0 -0
- data/{img/gicons → out/images}/marker88.png +0 -0
- data/{img/gicons → out/images}/marker89.png +0 -0
- data/{img/gicons → out/images}/marker9.png +0 -0
- data/{img/gicons → out/images}/marker90.png +0 -0
- data/{img/gicons → out/images}/marker91.png +0 -0
- data/{img/gicons → out/images}/marker92.png +0 -0
- data/{img/gicons → out/images}/marker93.png +0 -0
- data/{img/gicons → out/images}/marker94.png +0 -0
- data/{img/gicons → out/images}/marker95.png +0 -0
- data/{img/gicons → out/images}/marker96.png +0 -0
- data/{img/gicons → out/images}/marker97.png +0 -0
- data/{img/gicons → out/images}/marker98.png +0 -0
- data/{img/gicons → out/images}/marker99.png +0 -0
- data/{img/gicons → out/images}/markerA.png +0 -0
- data/{img/gicons → out/images}/markerB.png +0 -0
- data/{img/gicons → out/images}/markerC.png +0 -0
- data/{img/gicons → out/images}/markerD.png +0 -0
- data/{img/gicons → out/images}/markerE.png +0 -0
- data/{img/gicons → out/images}/markerF.png +0 -0
- data/{img/gicons → out/images}/markerG.png +0 -0
- data/{img/gicons → out/images}/markerH.png +0 -0
- data/{img/gicons → out/images}/markerI.png +0 -0
- data/{img/gicons → out/images}/markerJ.png +0 -0
- data/{img/gicons → out/images}/mm_20_red.png +0 -0
- data/{img/gicons → out/images}/mm_20_shadow.png +0 -0
- data/{img/gicons → out/images}/shadow50.png +0 -0
- data/rakefile.rb +79 -0
- data/samples.sh +21 -0
- data/samples/2008_04_27_13_49_50_tcx.csv +2449 -0
- data/samples/2008_04_27_13_49_50_tcx.xml +24560 -0
- data/samples/2009_01_01_14_45_00_tcx.xml +10630 -0
- data/samples/ballantyne.csv +27 -0
- data/samples/ballantyne.gpx +117 -0
- data/samples/ballantyne.kml +91 -0
- data/samples/big_sur_marathon.html +2766 -0
- data/samples/big_sur_marathon.kml +685 -0
- data/samples/build_gem_test_results.txt +6 -0
- data/samples/crowders_mtn_hike.csv +1065 -0
- data/samples/crowders_mtn_hike.html +1283 -0
- data/samples/crowders_mtn_hike.log +1 -0
- data/samples/cucumber_test_results.txt +302 -0
- data/samples/davidson1.csv +1 -0
- data/samples/davidson1.html +75 -0
- data/samples/davidson_1_point_tcx.csv +0 -0
- data/samples/doc.kml +49 -0
- data/samples/gps_track_log_asheville_mt_pisgah.txt +1 -0
- data/samples/gps_track_logs.txt +1 -0
- data/samples/install_test_results.txt +81 -0
- data/samples/mt_pisgah.txt +1 -0
- data/samples/rspec_test_results.txt +5 -0
- data/setup.rb +66 -0
- data/spec/gooby_base_object_spec.rb +116 -0
- data/spec/gooby_counter_hash_spec.rb +34 -0
- data/spec/gooby_dttm_spec.rb +40 -0
- data/spec/gooby_spec_helper.rb +9 -0
- data/spec/gooby_xml_object_spec.rb +32 -0
- metadata +225 -226
- data/bin/code_scan.rb +0 -16
- data/bin/gooby_been_there.rb +0 -33
- data/bin/gooby_config.rb +0 -24
- data/bin/gooby_csv_validation.rb +0 -50
- data/bin/gooby_first_trackpoints_as_poi.rb +0 -31
- data/bin/gooby_gen_gmap.rb +0 -20
- data/bin/gooby_parser.rb +0 -21
- data/bin/gooby_splitter.rb +0 -21
- data/bin/gooby_version.rb +0 -20
- data/bin/run_all.sh +0 -33
- data/bin/run_been_there.sh +0 -19
- data/bin/run_config.sh +0 -12
- data/bin/run_csv_validation.sh +0 -15
- data/bin/run_db_gen.sh +0 -11
- data/bin/run_db_load.sh +0 -11
- data/bin/run_first_trackpoints_as_poi.sh +0 -16
- data/bin/run_gen_gmaps.sh +0 -21
- data/bin/run_parse_full.sh +0 -45
- data/bin/run_parse_samples.sh +0 -21
- data/bin/run_split.sh +0 -24
- data/bin/run_version.sh +0 -12
- data/data/20050305_corporate_cup_hm.csv +0 -251
- data/data/20050305_corporate_cup_hm.xml +0 -2208
- data/data/20050430_nashville_marathon.xml +0 -10043
- data/data/20050430_nashville_marathon_km.csv +0 -1208
- data/data/20060115_phoenix_marathon.csv +0 -1280
- data/data/20060115_phoenix_marathon.xml +0 -10620
- data/data/20070101_davidson_11m.csv +0 -251
- data/data/20070101_davidson_11m.xml +0 -2020
- data/data/20070505_davidson_5k.xml +0 -2875
- data/data/20070505_davidson_5k_km.csv +0 -286
- data/data/hrm1.csv +0 -5
- data/img/gicons/readme.txt +0 -14
- data/lib/gooby_code_scanner.rb +0 -288
- data/lib/gooby_command.rb +0 -210
- data/lib/gooby_course.rb +0 -117
- data/lib/gooby_csv_point.rb +0 -71
- data/lib/gooby_csv_reader.rb +0 -71
- data/lib/gooby_csv_run.rb +0 -28
- data/lib/gooby_delim_line.rb +0 -42
- data/lib/gooby_duration.rb +0 -86
- data/lib/gooby_forerunner_xml_parser.rb +0 -191
- data/lib/gooby_forerunner_xml_splitter.rb +0 -115
- data/lib/gooby_history.rb +0 -41
- data/lib/gooby_kernel.rb +0 -163
- data/lib/gooby_line.rb +0 -80
- data/lib/gooby_object.rb +0 -22
- data/lib/gooby_point.rb +0 -172
- data/lib/gooby_run.rb +0 -213
- data/lib/gooby_simple_xml_parser.rb +0 -50
- data/lib/gooby_test_helper.rb +0 -23
- data/lib/gooby_track.rb +0 -47
- data/lib/gooby_track_point.rb +0 -229
- data/lib/gooby_training_center_xml_parser.rb +0 -224
- data/lib/gooby_training_center_xml_splitter.rb +0 -116
- data/lib/split_code.sh +0 -29
- data/samples/20050305_corporate_cup_hm.html +0 -450
- data/samples/20050430_nashville_marathon.html +0 -1668
- data/samples/20060115_phoenix_marathon.html +0 -1596
- data/samples/20070101_davidson_11m.html +0 -432
- data/samples/20070505_davidson_5k.html +0 -413
- data/samples/been_there.txt +0 -92
- data/samples/hrm1.html +0 -87
- data/sql/gooby.ddl +0 -60
- data/sql/gooby_load.dml +0 -62
@@ -0,0 +1,46 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
Gooby = Google APIs + Ruby. Copyright 2009 by Chris Joakim.
|
4
|
+
Gooby is available under GNU General Public License (GPL) license.
|
5
|
+
|
6
|
+
=end
|
7
|
+
|
8
|
+
class GoobyBaseObject
|
9
|
+
|
10
|
+
include GoobyEnvironment
|
11
|
+
include GoobyIntrospection
|
12
|
+
include GoobyIO
|
13
|
+
|
14
|
+
UOM_MILES = "m"
|
15
|
+
UOM_KILOMETERS = "k"
|
16
|
+
UOM_YARDS = "y"
|
17
|
+
KILOMETERS_PER_MILE = 1.61290322581
|
18
|
+
YARDS_PER_MILE = 1760.0
|
19
|
+
MILES_PER_KILOMETER = 0.62
|
20
|
+
YARDS_PER_KILOMETER = 1091.2
|
21
|
+
METERS_PER_FOOT = 3.281 # see http://www.chrismanual.com/Intro/convfact.htm
|
22
|
+
SECONDS_PER_HOUR = 3600.0
|
23
|
+
|
24
|
+
@@config = nil
|
25
|
+
|
26
|
+
def self.set_config(c)
|
27
|
+
@@config = c
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.get_config
|
31
|
+
@@config
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.config_value(name)
|
35
|
+
@@config[name]
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.boolean_config_value(name)
|
39
|
+
value = config_value(name)
|
40
|
+
return false if value.nil?
|
41
|
+
return true if value == true
|
42
|
+
return true if value == 'true'
|
43
|
+
false
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
Gooby = Google APIs + Ruby. Copyright 2009 by Chris Joakim.
|
4
|
+
Gooby is available under GNU General Public License (GPL) license.
|
5
|
+
|
6
|
+
---
|
7
|
+
|
8
|
+
This abstract class implements common SAX-event and error handling for XML parsers.
|
9
|
+
'libxml-ruby' gem version 0.9.7 is required.
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'libxml'
|
14
|
+
|
15
|
+
class GoobyBaseSaxParser
|
16
|
+
|
17
|
+
include LibXML
|
18
|
+
include XML::SaxParser::Callbacks
|
19
|
+
|
20
|
+
attr_reader :xml, :list, :current_tagname, :mappings
|
21
|
+
attr_reader :exception, :end_reached, :error
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
@parser = XML::SaxParser.new
|
25
|
+
@parser.callbacks = self
|
26
|
+
@list, @current_text, @current_tagname = [], '', ''
|
27
|
+
@exception, @error, @end_reached = nil, nil, false
|
28
|
+
@mappings = {}
|
29
|
+
subclass_initialize
|
30
|
+
# XML::Error.set_handler do | e |
|
31
|
+
# self.set_error(e)
|
32
|
+
# end
|
33
|
+
end
|
34
|
+
|
35
|
+
def subclass_initialize
|
36
|
+
# subclasses should override this method. set @mappings and other variables.
|
37
|
+
end
|
38
|
+
|
39
|
+
def set_error(e)
|
40
|
+
@error = "#{e}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def process_file(file)
|
44
|
+
process_xml(File.read(file))
|
45
|
+
end
|
46
|
+
|
47
|
+
def process_xml(xml_string)
|
48
|
+
begin
|
49
|
+
@xml = xml_string
|
50
|
+
@parser.string = @xml
|
51
|
+
@parser.parse
|
52
|
+
rescue Exception => e
|
53
|
+
@exception = "#{e.class} #{e.message}"
|
54
|
+
raise e
|
55
|
+
end
|
56
|
+
@list
|
57
|
+
end
|
58
|
+
|
59
|
+
# Indicates if an Exception, though not necessarily an Error, has occurred.
|
60
|
+
def has_exception?
|
61
|
+
(@exception == nil) ? false : true
|
62
|
+
end
|
63
|
+
|
64
|
+
# Indicates if an Error, though not necessarily an Exception, has occurred.
|
65
|
+
def has_error?
|
66
|
+
(@error == nil) ? false : true
|
67
|
+
end
|
68
|
+
|
69
|
+
# Indicates if the ending 'on_end_document' handler method has been called or not.
|
70
|
+
def end_reached?
|
71
|
+
@end_reached
|
72
|
+
end
|
73
|
+
|
74
|
+
def on_characters(chars)
|
75
|
+
@current_text << chars if chars
|
76
|
+
end
|
77
|
+
|
78
|
+
def on_cdata_block(cdata)
|
79
|
+
@current_text << cdata if cdata
|
80
|
+
end
|
81
|
+
|
82
|
+
def get_current_text
|
83
|
+
(@current_text) ? @current_text.strip : ''
|
84
|
+
end
|
85
|
+
|
86
|
+
def on_error(msg)
|
87
|
+
@error = "#{msg}"
|
88
|
+
end
|
89
|
+
|
90
|
+
def on_end_document
|
91
|
+
@end_reached = true
|
92
|
+
XML::Error.reset_handler
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
data/lib/gooby_configuration.rb
CHANGED
@@ -1,123 +1,41 @@
|
|
1
1
|
=begin
|
2
2
|
|
3
|
-
Gooby = Google APIs + Ruby
|
4
|
-
Gooby - Copyright 2007 by Chris Joakim.
|
3
|
+
Gooby = Google APIs + Ruby. Copyright 2009 by Chris Joakim.
|
5
4
|
Gooby is available under GNU General Public License (GPL) license.
|
6
5
|
|
7
6
|
=end
|
8
7
|
|
9
|
-
module
|
10
|
-
|
11
|
-
=begin
|
12
|
-
|
13
|
-
This is a singleton class whose values are loaded from a YAML file when your
|
14
|
-
GoobyCommand class is created. The default filename is 'gooby_config.yaml"'.
|
15
|
-
|
16
|
-
The YAML file contains configuration parameters, such as your Google Map key,
|
17
|
-
map HTML options, points of interest, and courses.
|
18
|
-
|
19
|
-
=end
|
20
|
-
class Configuration < GoobyObject
|
21
|
-
|
22
|
-
@@singleton_instance = nil
|
23
|
-
|
24
|
-
attr_reader :yaml_filename, :configuration
|
25
|
-
|
26
|
-
private_class_method :new
|
27
|
-
|
28
|
-
def Configuration.init(yaml_filename='gooby_config.yaml')
|
29
|
-
return @@singleton_instance if @@singleton_instance
|
30
|
-
@@singleton_instance = new(yaml_filename)
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.get_config
|
34
|
-
@@singleton_instance
|
35
|
-
end
|
36
|
-
|
37
|
-
def initialize(yaml_filename)
|
38
|
-
@yaml_filename = yaml_filename
|
39
|
-
File.open("#{@yaml_filename}") { |fn| @configuration = YAML::load(fn) }
|
40
|
-
end
|
41
|
-
|
42
|
-
def get(name)
|
43
|
-
if name == nil
|
44
|
-
return ''
|
45
|
-
end
|
46
|
-
s = @configuration["#{name}"]
|
47
|
-
|
48
|
-
# Provide "sensible defaults".
|
49
|
-
if s == nil
|
50
|
-
if (name == '')
|
51
|
-
return ''
|
52
|
-
elsif (name == 'english_metric')
|
53
|
-
return 'english'
|
54
|
-
elsif (name == 'gmap_first_tkpt_number')
|
55
|
-
return 1
|
56
|
-
elsif (name == 'gmap_last_tkpt_number')
|
57
|
-
return 5000
|
58
|
-
elsif (name == 'gmap_map_element_id')
|
59
|
-
return 'map'
|
60
|
-
elsif (name == 'gmap_height')
|
61
|
-
return '600'
|
62
|
-
elsif (name == 'gmap_icon_url_base')
|
63
|
-
return 'http://www.your-web-site.com/gicons/'
|
64
|
-
elsif (name == 'gmap_key')
|
65
|
-
return 'enter your Google Map Key here'
|
66
|
-
elsif (name == 'gmap_type_control')
|
67
|
-
return true
|
68
|
-
elsif (name == 'gmap_approx_max_points')
|
69
|
-
return '200'
|
70
|
-
elsif (name == 'gmap_gen_comments')
|
71
|
-
return true
|
72
|
-
elsif (name == 'gmap_size_control')
|
73
|
-
return nil
|
74
|
-
elsif (name == 'gmap_type')
|
75
|
-
return 'G_NORMAL_MAP'
|
76
|
-
elsif (name == 'gmap_zoom_level')
|
77
|
-
return 5
|
78
|
-
else
|
79
|
-
return ''
|
80
|
-
end
|
81
|
-
end
|
82
|
-
s
|
83
|
-
end
|
84
|
-
|
85
|
-
def print_all
|
86
|
-
@configuration.keys.sort.each { |key|
|
87
|
-
value = get(key)
|
88
|
-
puts "#{key}: #{value}"
|
89
|
-
}
|
90
|
-
end
|
91
|
-
|
92
|
-
def print_all_poi
|
93
|
-
@configuration.keys.sort.each { |key|
|
94
|
-
if (key.match(/poi[\.]/))
|
95
|
-
val = @configuration["#{key}"]
|
96
|
-
poi = Point.new(val)
|
97
|
-
puts poi.to_s
|
98
|
-
end
|
99
|
-
}
|
100
|
-
end
|
101
|
-
|
102
|
-
def get_poi(number)
|
103
|
-
val = @configuration["poi.#{number}"]
|
104
|
-
(val) ? Point.new(val) : nil
|
105
|
-
end
|
106
|
-
|
107
|
-
def get_course(number)
|
108
|
-
val = @configuration["course.#{number}"]
|
109
|
-
(val) ? Course.new(val) : nil
|
110
|
-
end
|
111
|
-
|
112
|
-
def size
|
113
|
-
@configuration.size
|
114
|
-
end
|
8
|
+
module GoobyConfiguration
|
115
9
|
|
116
|
-
|
117
|
-
|
118
|
-
|
10
|
+
def gooby_home
|
11
|
+
ENV['GOOBY_HOME']
|
12
|
+
end
|
13
|
+
|
14
|
+
def read_configuration(additional_config_file)
|
15
|
+
|
16
|
+
# First load the base config file into @configuration
|
17
|
+
base_config_file = "#{gooby_home}/config/gooby_config.yaml"
|
18
|
+
if File.exist?(base_config_file)
|
19
|
+
puts "loading base configuration file #{base_config_file}"
|
20
|
+
File.open(base_config_file) { | f | @configuration = YAML::load(f) }
|
21
|
+
else
|
22
|
+
puts "ERROR: the base configuration file does not exist - #{base_config_file}"
|
23
|
+
end
|
24
|
+
|
25
|
+
# Optionally load a second map-specific config file and overlay any
|
26
|
+
# values in the base configuration.
|
27
|
+
if (additional_config_file) && (File.exist?(additional_config_file))
|
28
|
+
puts "loading additional configuration file #{additional_config_file}"
|
29
|
+
File.open(additional_config_file) { | f | @additional_config = YAML::load(f) }
|
30
|
+
@additional_config.keys.each { | key |
|
31
|
+
value = @additional_config[key]
|
32
|
+
@configuration[key] = value
|
33
|
+
# puts "'#{key}' overlaid with '#{value}'"
|
34
|
+
}
|
35
|
+
else
|
36
|
+
puts "ERROR: the additional configuration file does not exist - #{additional_config_file}"
|
119
37
|
end
|
120
|
-
|
121
|
-
end
|
122
|
-
|
123
|
-
end
|
38
|
+
GoobyBaseObject.set_config(@configuration)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
data/lib/gooby_counter_hash.rb
CHANGED
@@ -1,95 +1,36 @@
|
|
1
1
|
=begin
|
2
2
|
|
3
|
-
Gooby = Google APIs + Ruby
|
4
|
-
Gooby - Copyright 2007 by Chris Joakim.
|
3
|
+
Gooby = Google APIs + Ruby. Copyright 2009 by Chris Joakim.
|
5
4
|
Gooby is available under GNU General Public License (GPL) license.
|
6
5
|
|
7
6
|
=end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
This class wrappers a Hash object and provides increment/decrement functionality
|
13
|
-
for a given key. It is used to sum the number of things (i.e. - xml tags) in a
|
14
|
-
collection.
|
15
|
-
=end
|
16
|
-
|
17
|
-
class CounterHash < GoobyObject
|
18
|
-
|
19
|
-
def initialize
|
20
|
-
@hash = Hash.new(0)
|
21
|
-
end
|
22
|
-
|
23
|
-
def size
|
24
|
-
@hash.size
|
25
|
-
end
|
26
|
-
|
27
|
-
# Return the Integer count for the given key; zero default.
|
28
|
-
def value(key)
|
29
|
-
(@hash.has_key?(key)) ? @hash[key] : 0
|
30
|
-
end
|
31
|
-
|
32
|
-
# Increment the count for the given key.
|
33
|
-
def increment(key)
|
34
|
-
if key == nil
|
35
|
-
return
|
36
|
-
end
|
37
|
-
if (@hash.has_key?(key))
|
38
|
-
val = @hash[key]
|
39
|
-
@hash[key] = val + 1
|
40
|
-
else
|
41
|
-
@hash[key] = 1
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def increment_tokens(text)
|
46
|
-
tokens = tokenize(text)
|
47
|
-
tokens.each { |token| increment(token) }
|
48
|
-
end
|
49
|
-
|
50
|
-
# Decrement the count for the given key.
|
51
|
-
def decrement(key)
|
52
|
-
if key == nil
|
53
|
-
return
|
54
|
-
end
|
55
|
-
if (@hash.has_key?(key))
|
56
|
-
val = @hash[key]
|
57
|
-
@hash[key] = val - 1
|
58
|
-
else
|
59
|
-
@hash[key] = -1
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
# Return an Array of the sorted keys.
|
64
|
-
def sorted_keys
|
65
|
-
@hash.keys.sort
|
66
|
-
end
|
67
|
-
|
68
|
-
# Return a String containing all key=val pairs.
|
69
|
-
def to_s
|
70
|
-
s = "CHash:"
|
71
|
-
sorted_keys.each { |key|
|
72
|
-
val = @hash[key]
|
73
|
-
s << " key: [#{key}] val: [#{val}]\n"
|
74
|
-
}
|
75
|
-
s
|
76
|
-
end
|
77
|
-
|
78
|
-
# Return an XML String containing all key=val pairs, optionally aligned.
|
79
|
-
def to_xml(aligned=false)
|
80
|
-
s = "<CHash>"
|
81
|
-
sorted_keys.each { |key|
|
82
|
-
val = @hash[key]
|
83
|
-
(aligned) ? s << "\n " : s << ''
|
84
|
-
s << " <entry key='#{key}' value='#{val}'/>"
|
85
|
-
}
|
86
|
-
if aligned
|
87
|
-
s << "\n "
|
88
|
-
end
|
89
|
-
s << " </CHash>"
|
90
|
-
s
|
91
|
-
end
|
8
|
+
class GoobyCounterHash
|
9
|
+
|
10
|
+
attr_reader :hash
|
92
11
|
|
12
|
+
def initialize
|
13
|
+
@hash = Hash.new(0)
|
93
14
|
end
|
94
|
-
|
95
|
-
|
15
|
+
|
16
|
+
def increment(key)
|
17
|
+
new_value = @hash[key] + 1
|
18
|
+
@hash[key] = new_value
|
19
|
+
new_value
|
20
|
+
end
|
21
|
+
|
22
|
+
def decrement(key)
|
23
|
+
new_value = @hash[key] - 1
|
24
|
+
@hash[key] = new_value
|
25
|
+
new_value
|
26
|
+
end
|
27
|
+
|
28
|
+
def value(key)
|
29
|
+
@hash[key]
|
30
|
+
end
|
31
|
+
|
32
|
+
def sorted_keys
|
33
|
+
@hash.keys.sort
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
data/lib/gooby_dttm.rb
CHANGED
@@ -1,87 +1,109 @@
|
|
1
1
|
=begin
|
2
2
|
|
3
|
-
Gooby = Google APIs + Ruby
|
4
|
-
Gooby - Copyright 2007 by Chris Joakim.
|
3
|
+
Gooby = Google APIs + Ruby. Copyright 2009 by Chris Joakim.
|
5
4
|
Gooby is available under GNU General Public License (GPL) license.
|
6
5
|
|
7
|
-
|
6
|
+
---
|
8
7
|
|
9
|
-
|
8
|
+
Instances of this class represent a Date and Time as parsed from a value
|
9
|
+
such as '2006-01-15T13:41:40Z' in an XML file produced by a GPS device.
|
10
|
+
It wrappers a Time object.
|
10
11
|
|
11
|
-
=begin rdoc
|
12
|
-
Instances of this class represent a Date and Time as parsed from a value
|
13
|
-
such as '2006-01-15T13:41:40Z' in an XML file produced by a GPS device.
|
14
|
-
It wrappers both a DateTime and Time object.
|
15
12
|
=end
|
13
|
+
|
14
|
+
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
attr_accessor :rawdata, :dateTime, :time, :valid
|
16
|
+
class GoobyDtTm < GoobyBaseObject
|
20
17
|
|
21
|
-
|
22
|
-
def initialize(raw)
|
23
|
-
if raw
|
24
|
-
@rawdata = raw.strip
|
25
|
-
if @rawdata.size > 18
|
26
|
-
@date_time = DateTime.parse(@rawdata[0..18])
|
27
|
-
@time = Time.parse(@date_time.to_s)
|
28
|
-
@valid = true
|
29
|
-
else
|
30
|
-
@valid = false
|
31
|
-
end
|
32
|
-
else
|
33
|
-
@rawdata = ''
|
34
|
-
@valid = false
|
35
|
-
end
|
36
|
-
end
|
18
|
+
@@months = Hash.new('')
|
37
19
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
(
|
20
|
+
attr_accessor :time, :valid
|
21
|
+
|
22
|
+
def lookup_month(m)
|
23
|
+
if @@months.size == 0
|
24
|
+
@@months = Hash.new('') # 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
|
25
|
+
@@months['01'] = 'jan'
|
26
|
+
@@months['02'] = 'feb'
|
27
|
+
@@months['03'] = 'mar'
|
28
|
+
@@months['04'] = 'apr'
|
29
|
+
@@months['05'] = 'may'
|
30
|
+
@@months['06'] = 'jun'
|
31
|
+
@@months['07'] = 'jul'
|
32
|
+
@@months['08'] = 'aug'
|
33
|
+
@@months['09'] = 'sep'
|
34
|
+
@@months['10'] = 'oct'
|
35
|
+
@@months['11'] = 'nov'
|
36
|
+
@@months['12'] = 'dec'
|
43
37
|
end
|
38
|
+
@@months[m]
|
39
|
+
end
|
44
40
|
|
45
|
-
#
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
41
|
+
# The arg is a String like '2006-01-15T13:41:40Z'.
|
42
|
+
def initialize(raw)
|
43
|
+
@valid = false
|
44
|
+
if raw
|
45
|
+
a = raw.tr('TZ\-\:', ' ').strip.split
|
46
|
+
if a.size > 5
|
47
|
+
@time = Time.utc(a[0].to_i, lookup_month(a[1]), a[2].to_i, a[3].to_i, a[4].to_i, a[5].to_i)
|
48
|
+
@valid = true if @time
|
51
49
|
end
|
52
50
|
end
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_i
|
54
|
+
(@time) ? @time.to_i : invalid_time
|
55
|
+
end
|
56
|
+
|
57
|
+
def invalid_time
|
58
|
+
return -99999999
|
59
|
+
end
|
60
|
+
|
61
|
+
def yyyy_mm_dd
|
62
|
+
time.strftime("%Y-%m-%d")
|
63
|
+
end
|
64
|
+
|
65
|
+
def yyyy_mm_dd_hh_mm_ss(delim=' ')
|
66
|
+
time.strftime("#{yyyy_mm_dd}#{delim}#{hh_mm_ss}")
|
67
|
+
end
|
68
|
+
|
69
|
+
def hh_mm_ss
|
70
|
+
time.strftime("%H:%M:%S")
|
71
|
+
end
|
72
|
+
|
73
|
+
def seconds_diff(another_dttm)
|
74
|
+
if another_dttm
|
75
|
+
to_i - another_dttm.to_i
|
76
|
+
else
|
77
|
+
invalid_time
|
64
78
|
end
|
79
|
+
end
|
65
80
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
81
|
+
def hhmmss_diff(another_dttm)
|
82
|
+
if another_dttm
|
83
|
+
secs = seconds_diff(another_dttm).abs
|
84
|
+
hh = (secs / SECONDS_PER_HOUR).to_i
|
85
|
+
rem = secs - (hh * SECONDS_PER_HOUR)
|
86
|
+
mm = (rem / 60).to_i
|
87
|
+
ss = rem - (mm * 60).to_i
|
88
|
+
ss = 59 if ss > 59
|
89
|
+
"#{hh}:#{zero_pad(mm)}:#{zero_pad(ss.to_i)}"
|
90
|
+
else
|
91
|
+
'00:00:00'
|
74
92
|
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def to_s
|
96
|
+
"#{yyyy_mm_dd} #{hh_mm_ss} #{to_i}"
|
97
|
+
end
|
75
98
|
|
76
|
-
|
77
|
-
"#{@rawdata}"
|
78
|
-
end
|
99
|
+
private
|
79
100
|
|
80
|
-
|
81
|
-
|
82
|
-
|
101
|
+
def zero_pad(val)
|
102
|
+
if (val.to_i < 10)
|
103
|
+
return '0' + val.to_s
|
104
|
+
else
|
105
|
+
return '' + val.to_s
|
83
106
|
end
|
107
|
+
end
|
84
108
|
|
85
|
-
|
86
|
-
|
87
|
-
end # end of module
|
109
|
+
end
|