gooby 0.9.3
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.
- data/README +242 -0
- data/bin/example_usage.rb +38 -0
- data/bin/tests_gen.rb +16 -0
- data/data/20050305_corporate_cup_hm.csv +251 -0
- data/data/20050305_corporate_cup_hm.xml +2208 -0
- data/data/20050430_nashville_marathon.csv +1208 -0
- data/data/20050430_nashville_marathon.xml +10043 -0
- data/data/20051119_dowd_ymca_hm.csv +251 -0
- data/data/20051119_dowd_ymca_hm.xml +2210 -0
- data/data/20051124_hyatt_turkey_trot_8K.csv +321 -0
- data/data/20051124_hyatt_turkey_trot_8K.xml +2651 -0
- data/data/2007_03_03.tcx +6207 -0
- data/data/forerunner_2007.xml +259014 -0
- data/data/geo_data.txt +171 -0
- data/data/phx.csv +1280 -0
- data/data/phx.xml +10620 -0
- data/data/run_2007_01_01_16_38_27.xml +2020 -0
- data/data/run_2007_01_06_15_27_31.xml +2020 -0
- data/data/run_2007_01_10_12_25_47.xml +820 -0
- data/data/run_2007_01_10_22_44_54.csv +112 -0
- data/data/run_2007_01_10_22_44_54.xml +908 -0
- data/data/run_2007_01_11_10_48_45.xml +1292 -0
- data/data/run_2007_01_13_15_37_06.xml +1964 -0
- data/data/run_2007_01_14_15_46_02.xml +1368 -0
- data/data/run_2007_01_15_14_01_48.xml +1868 -0
- data/data/run_2007_01_20_16_22_05.xml +1702 -0
- data/data/run_2007_01_27_17_32_13.xml +3626 -0
- data/data/run_2007_01_28_19_14_52.xml +2538 -0
- data/data/run_2007_02_03_14_30_20.xml +2016 -0
- data/data/run_2007_02_04_18_02_30.xml +1476 -0
- data/data/run_2007_02_17_16_29_35.xml +1236 -0
- data/data/run_2007_02_19_14_44_33.xml +1816 -0
- data/data/run_2007_02_23_15_53_55.xml +36 -0
- data/data/run_2007_02_23_15_55_20.xml +1296 -0
- data/data/run_2007_02_24_15_01_35.csv +484 -0
- data/data/run_2007_02_24_15_01_35.xml +3884 -0
- data/data/test1.txt +4 -0
- data/img/gicons/blank.png +0 -0
- data/img/gicons/dd-end.png +0 -0
- data/img/gicons/dd-start.png +0 -0
- data/img/gicons/marker.png +0 -0
- data/img/gicons/marker0.png +0 -0
- data/img/gicons/marker00.png +0 -0
- data/img/gicons/marker01.png +0 -0
- data/img/gicons/marker02.png +0 -0
- data/img/gicons/marker03.png +0 -0
- data/img/gicons/marker04.png +0 -0
- data/img/gicons/marker05.png +0 -0
- data/img/gicons/marker06.png +0 -0
- data/img/gicons/marker07.png +0 -0
- data/img/gicons/marker08.png +0 -0
- data/img/gicons/marker09.png +0 -0
- data/img/gicons/marker1.png +0 -0
- data/img/gicons/marker10.png +0 -0
- data/img/gicons/marker11.png +0 -0
- data/img/gicons/marker12.png +0 -0
- data/img/gicons/marker13.png +0 -0
- data/img/gicons/marker14.png +0 -0
- data/img/gicons/marker15.png +0 -0
- data/img/gicons/marker16.png +0 -0
- data/img/gicons/marker17.png +0 -0
- data/img/gicons/marker18.png +0 -0
- data/img/gicons/marker19.png +0 -0
- data/img/gicons/marker2.png +0 -0
- data/img/gicons/marker20.png +0 -0
- data/img/gicons/marker21.png +0 -0
- data/img/gicons/marker22.png +0 -0
- data/img/gicons/marker23.png +0 -0
- data/img/gicons/marker24.png +0 -0
- data/img/gicons/marker25.png +0 -0
- data/img/gicons/marker26.png +0 -0
- data/img/gicons/marker27.png +0 -0
- data/img/gicons/marker28.png +0 -0
- data/img/gicons/marker29.png +0 -0
- data/img/gicons/marker3.png +0 -0
- data/img/gicons/marker30.png +0 -0
- data/img/gicons/marker31.png +0 -0
- data/img/gicons/marker32.png +0 -0
- data/img/gicons/marker33.png +0 -0
- data/img/gicons/marker34.png +0 -0
- data/img/gicons/marker35.png +0 -0
- data/img/gicons/marker36.png +0 -0
- data/img/gicons/marker37.png +0 -0
- data/img/gicons/marker38.png +0 -0
- data/img/gicons/marker39.png +0 -0
- data/img/gicons/marker4.png +0 -0
- data/img/gicons/marker40.png +0 -0
- data/img/gicons/marker41.png +0 -0
- data/img/gicons/marker42.png +0 -0
- data/img/gicons/marker43.png +0 -0
- data/img/gicons/marker44.png +0 -0
- data/img/gicons/marker45.png +0 -0
- data/img/gicons/marker46.png +0 -0
- data/img/gicons/marker47.png +0 -0
- data/img/gicons/marker48.png +0 -0
- data/img/gicons/marker49.png +0 -0
- data/img/gicons/marker5.png +0 -0
- data/img/gicons/marker50.png +0 -0
- data/img/gicons/marker51.png +0 -0
- data/img/gicons/marker52.png +0 -0
- data/img/gicons/marker53.png +0 -0
- data/img/gicons/marker54.png +0 -0
- data/img/gicons/marker55.png +0 -0
- data/img/gicons/marker56.png +0 -0
- data/img/gicons/marker57.png +0 -0
- data/img/gicons/marker58.png +0 -0
- data/img/gicons/marker59.png +0 -0
- data/img/gicons/marker6.png +0 -0
- data/img/gicons/marker60.png +0 -0
- data/img/gicons/marker61.png +0 -0
- data/img/gicons/marker62.png +0 -0
- data/img/gicons/marker63.png +0 -0
- data/img/gicons/marker64.png +0 -0
- data/img/gicons/marker65.png +0 -0
- data/img/gicons/marker66.png +0 -0
- data/img/gicons/marker67.png +0 -0
- data/img/gicons/marker68.png +0 -0
- data/img/gicons/marker69.png +0 -0
- data/img/gicons/marker7.png +0 -0
- data/img/gicons/marker70.png +0 -0
- data/img/gicons/marker71.png +0 -0
- data/img/gicons/marker72.png +0 -0
- data/img/gicons/marker73.png +0 -0
- data/img/gicons/marker74.png +0 -0
- data/img/gicons/marker75.png +0 -0
- data/img/gicons/marker76.png +0 -0
- data/img/gicons/marker77.png +0 -0
- data/img/gicons/marker78.png +0 -0
- data/img/gicons/marker79.png +0 -0
- data/img/gicons/marker8.png +0 -0
- data/img/gicons/marker80.png +0 -0
- data/img/gicons/marker81.png +0 -0
- data/img/gicons/marker82.png +0 -0
- data/img/gicons/marker83.png +0 -0
- data/img/gicons/marker84.png +0 -0
- data/img/gicons/marker85.png +0 -0
- data/img/gicons/marker86.png +0 -0
- data/img/gicons/marker87.png +0 -0
- data/img/gicons/marker88.png +0 -0
- data/img/gicons/marker89.png +0 -0
- data/img/gicons/marker9.png +0 -0
- data/img/gicons/marker90.png +0 -0
- data/img/gicons/marker91.png +0 -0
- data/img/gicons/marker92.png +0 -0
- data/img/gicons/marker93.png +0 -0
- data/img/gicons/marker94.png +0 -0
- data/img/gicons/marker95.png +0 -0
- data/img/gicons/marker96.png +0 -0
- data/img/gicons/marker97.png +0 -0
- data/img/gicons/marker98.png +0 -0
- data/img/gicons/marker99.png +0 -0
- data/img/gicons/markerA.png +0 -0
- data/img/gicons/markerB.png +0 -0
- data/img/gicons/markerC.png +0 -0
- data/img/gicons/markerD.png +0 -0
- data/img/gicons/markerE.png +0 -0
- data/img/gicons/markerF.png +0 -0
- data/img/gicons/markerG.png +0 -0
- data/img/gicons/markerH.png +0 -0
- data/img/gicons/markerI.png +0 -0
- data/img/gicons/markerJ.png +0 -0
- data/img/gicons/mm_20_red.png +0 -0
- data/img/gicons/mm_20_shadow.png +0 -0
- data/img/gicons/readme.txt +11 -0
- data/img/gicons/shadow50.png +0 -0
- data/lib/gooby/cls_counter_hash.rb +78 -0
- data/lib/gooby/cls_delim_line.rb +35 -0
- data/lib/gooby/cls_dttm.rb +79 -0
- data/lib/gooby/cls_duration.rb +79 -0
- data/lib/gooby/cls_forerunner_xml_parser.rb +178 -0
- data/lib/gooby/cls_forerunner_xml_splitter.rb +109 -0
- data/lib/gooby/cls_geo_data.rb +181 -0
- data/lib/gooby/cls_gooby_command.rb +35 -0
- data/lib/gooby/cls_gooby_object.rb +18 -0
- data/lib/gooby/cls_google_map_generator.rb +363 -0
- data/lib/gooby/cls_history.rb +33 -0
- data/lib/gooby/cls_lap.rb +22 -0
- data/lib/gooby/cls_line.rb +75 -0
- data/lib/gooby/cls_options.rb +67 -0
- data/lib/gooby/cls_position.rb +44 -0
- data/lib/gooby/cls_run.rb +194 -0
- data/lib/gooby/cls_simple_xml_parser.rb +41 -0
- data/lib/gooby/cls_test_regen.rb +182 -0
- data/lib/gooby/cls_track.rb +47 -0
- data/lib/gooby/cls_trackpoint.rb +200 -0
- data/lib/gooby/mod_introspect.rb +26 -0
- data/lib/gooby/mod_io.rb +58 -0
- data/lib/gooby/mod_project_info.rb +80 -0
- data/lib/gooby/mod_string.rb +19 -0
- data/lib/gooby/mod_test_helper.rb +15 -0
- data/lib/gooby.rb +2265 -0
- data/pkg/code_header.txt +21 -0
- data/pkg/pkg.rb +236 -0
- data/pkg/test_header.txt +19 -0
- data/samples/20041113_richmond_marathon.html +532 -0
- data/samples/20050305_corporate_cup_hm.html +448 -0
- data/samples/20050430_nashville_marathon.html +530 -0
- data/samples/gps_point_capture.html +54 -0
- data/samples/phoenix_marathon.html +542 -0
- data/samples/run_2007_01_10_22_44_54.html +201 -0
- data/samples/run_2007_02_24_15_01_35.html +298 -0
- data/tests/tc_cls_counter_hash.rb +107 -0
- data/tests/tc_cls_delim_line.rb +74 -0
- data/tests/tc_cls_dttm.rb +131 -0
- data/tests/tc_cls_duration.rb +51 -0
- data/tests/tc_cls_forerunner_xml_parser.rb +70 -0
- data/tests/tc_cls_geo_data.xxx +71 -0
- data/tests/tc_cls_gooby_object.rb +26 -0
- data/tests/tc_cls_google_map_generator.rb +109 -0
- data/tests/tc_cls_history.rb +46 -0
- data/tests/tc_cls_lap.rb +38 -0
- data/tests/tc_cls_line.rb +110 -0
- data/tests/tc_cls_options.rb +79 -0
- data/tests/tc_cls_position.rb +66 -0
- data/tests/tc_cls_run.rb +142 -0
- data/tests/tc_cls_simple_xml_parser.rb +50 -0
- data/tests/tc_cls_track.rb +70 -0
- data/tests/tc_cls_trackpoint.rb +145 -0
- data/tests/tc_mod_introspect.rb +32 -0
- data/tests/tc_mod_io.rb +53 -0
- data/tests/tc_mod_project_info.rb +79 -0
- data/tests/tc_mod_string.rb +58 -0
- data/tests/ts_gooby.rb +1237 -0
- metadata +270 -0
data/data/test1.txt
ADDED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
Please do NOT use the 'joakim-systems' URL for these images on your site,
|
|
3
|
+
copy them to your webserver instead!
|
|
4
|
+
|
|
5
|
+
See the following URLs where icons were be obtained.
|
|
6
|
+
|
|
7
|
+
http://www.google.com/mapfiles/dd-start.png
|
|
8
|
+
http://www.google.com/mapfiles/dd-end.png
|
|
9
|
+
http://www.google.com/mapfiles/marker[A..J].png
|
|
10
|
+
|
|
11
|
+
http://mapki.com/index.php?title=Icon_Image_Sets
|
|
Binary file
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
module Gooby
|
|
2
|
+
|
|
3
|
+
=begin rdoc
|
|
4
|
+
This class wrappers a Hash object and provides increment/decrement functionality
|
|
5
|
+
for a given key. It is used to sum the number of things (i.e. - xml tags) in a
|
|
6
|
+
collection.
|
|
7
|
+
=end
|
|
8
|
+
|
|
9
|
+
class CounterHash < GoobyObject
|
|
10
|
+
|
|
11
|
+
def initialize
|
|
12
|
+
@hash = Hash.new(0)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Return the Integer count for the given key; zero default.
|
|
16
|
+
def value(key)
|
|
17
|
+
(@hash.has_key?(key)) ? @hash[key] : 0
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Increment the count for the given key.
|
|
21
|
+
def increment(key)
|
|
22
|
+
if key == nil
|
|
23
|
+
return
|
|
24
|
+
end
|
|
25
|
+
if (@hash.has_key?(key))
|
|
26
|
+
val = @hash[key]
|
|
27
|
+
@hash[key] = val + 1
|
|
28
|
+
else
|
|
29
|
+
@hash[key] = 1
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Decrement the count for the given key.
|
|
34
|
+
def decrement(key)
|
|
35
|
+
if key == nil
|
|
36
|
+
return
|
|
37
|
+
end
|
|
38
|
+
if (@hash.has_key?(key))
|
|
39
|
+
val = @hash[key]
|
|
40
|
+
@hash[key] = val - 1
|
|
41
|
+
else
|
|
42
|
+
@hash[key] = -1
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Return an Array of the sorted keys.
|
|
47
|
+
def sorted_keys
|
|
48
|
+
@hash.keys.sort
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Return a String containing all key=val pairs.
|
|
52
|
+
def to_s
|
|
53
|
+
s = "CHash:"
|
|
54
|
+
sorted_keys.each { |key|
|
|
55
|
+
val = @hash[key]
|
|
56
|
+
s << " key: [#{key}] val: [#{val}]"
|
|
57
|
+
}
|
|
58
|
+
s
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Return an XML String containing all key=val pairs, optionally aligned.
|
|
62
|
+
def to_xml(aligned=false)
|
|
63
|
+
s = "<CHash>"
|
|
64
|
+
sorted_keys.each { |key|
|
|
65
|
+
val = @hash[key]
|
|
66
|
+
(aligned) ? s << "\n " : s << ''
|
|
67
|
+
s << " <entry key='#{key}' value='#{val}'/>"
|
|
68
|
+
}
|
|
69
|
+
if aligned
|
|
70
|
+
s << "\n "
|
|
71
|
+
end
|
|
72
|
+
s << " </CHash>"
|
|
73
|
+
s
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end # end of module
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module Gooby
|
|
2
|
+
|
|
3
|
+
=begin rdoc
|
|
4
|
+
Instances of this class represent a delimited line of text, such as csv.
|
|
5
|
+
=end
|
|
6
|
+
|
|
7
|
+
class DelimLine < GoobyObject
|
|
8
|
+
|
|
9
|
+
attr_reader :line, :trim, :delim, :tokens
|
|
10
|
+
|
|
11
|
+
def initialize(line, trim=true, delim=default_delimiter)
|
|
12
|
+
@line = line
|
|
13
|
+
@trim = trim
|
|
14
|
+
@delim = delim
|
|
15
|
+
@tokens = @line.split(@delim)
|
|
16
|
+
if trim
|
|
17
|
+
@tokens.each { | token | token.strip! }
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def as_trackpoint(num_idx, lat_idx, lng_idx, alt_idx, dttm_idx)
|
|
22
|
+
Trackpoint.new(@tokens[num_idx], @tokens[lat_idx], @tokens[lng_idx], @tokens[alt_idx], @tokens[dttm_idx])
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def is_comment?
|
|
26
|
+
@line.strip.match('^#') ? true : false
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def to_s
|
|
30
|
+
"DelimLine: length: #{@line.size} trim: #{@trim} delim: #{@delim} tokens: #{@tokens.size}"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end # end of module
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
module Gooby
|
|
2
|
+
|
|
3
|
+
=begin rdoc
|
|
4
|
+
Instances of this class represent a Date and Time as parsed from a value
|
|
5
|
+
such as '2006-01-15T13:41:40Z' in an XML file produced by a GPS device.
|
|
6
|
+
It wrappers both a DateTime and Time object.
|
|
7
|
+
=end
|
|
8
|
+
|
|
9
|
+
class DtTm < GoobyObject
|
|
10
|
+
|
|
11
|
+
attr_accessor :rawdata, :dateTime, :time, :valid
|
|
12
|
+
|
|
13
|
+
# Constructor; arg is a String like '2006-01-15T13:41:40Z'.
|
|
14
|
+
def initialize(raw)
|
|
15
|
+
if raw
|
|
16
|
+
@rawdata = raw.strip
|
|
17
|
+
if @rawdata.size > 18
|
|
18
|
+
@dateTime = DateTime.parse(@rawdata[0..18])
|
|
19
|
+
@time = Time.parse(@dateTime.to_s)
|
|
20
|
+
@valid = true
|
|
21
|
+
else
|
|
22
|
+
@valid = false
|
|
23
|
+
end
|
|
24
|
+
else
|
|
25
|
+
@rawdata = ''
|
|
26
|
+
@valid = false
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
public
|
|
31
|
+
|
|
32
|
+
# Return @time.to_i
|
|
33
|
+
def to_i()
|
|
34
|
+
(@time) ? @time.to_i : invalid_time
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Calculates and returns diff between another instance.
|
|
38
|
+
def seconds_diff(anotherDtTm)
|
|
39
|
+
if anotherDtTm
|
|
40
|
+
to_i - anotherDtTm.to_i
|
|
41
|
+
else
|
|
42
|
+
invalid_time
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def yyyy_mm_dd
|
|
47
|
+
@time.strftime("%Y-%m-%d")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def yyyy_mm_dd_hh_mm_ss
|
|
51
|
+
@time.strftime("%Y-%m-%d %H:%M:%S")
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def hh_mm_ss
|
|
55
|
+
@time.strftime("%H:%M:%S")
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Calculate and return time diff in 'hh:mm:ss' format.
|
|
59
|
+
def hhmmss_diff(anotherDtTm)
|
|
60
|
+
if anotherDtTm
|
|
61
|
+
t = @time - (anotherDtTm.to_i)
|
|
62
|
+
t.strftime("%H:%M:%S")
|
|
63
|
+
else
|
|
64
|
+
'??:??:??'
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def to_s
|
|
69
|
+
"#{@rawdata}"
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Return a String with state values for debugging.
|
|
73
|
+
def print_string
|
|
74
|
+
"DtTm: #{yyyy_mm_dd_hh_mm_ss} #{to_i} #{@rawdata}"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
end # end of module
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
module Gooby
|
|
2
|
+
|
|
3
|
+
=begin rdoc
|
|
4
|
+
Instances of this class represent the contents of a Forerunner extract
|
|
5
|
+
<Duration> tag, such as:
|
|
6
|
+
<Duration>PT507.870S</Duration>
|
|
7
|
+
=end
|
|
8
|
+
|
|
9
|
+
class Duration < GoobyObject
|
|
10
|
+
|
|
11
|
+
attr_accessor :rawdata, :seconds, :minutes, :mmss
|
|
12
|
+
|
|
13
|
+
# Constructor; arg is a String like 'PT507.870S'.
|
|
14
|
+
def initialize(raw)
|
|
15
|
+
if raw
|
|
16
|
+
@rawdata = scrub(raw)
|
|
17
|
+
@seconds = @rawdata.to_f
|
|
18
|
+
@minutes = @seconds / 60
|
|
19
|
+
@base_min = @minutes.floor
|
|
20
|
+
@frac_min = @minutes - @base_min
|
|
21
|
+
@frac_sec = @frac_min * 60
|
|
22
|
+
|
|
23
|
+
@mmss = ''
|
|
24
|
+
if (@base_min < 10)
|
|
25
|
+
@mmss << "0#{@base_min}:"
|
|
26
|
+
else
|
|
27
|
+
@mmss << "#{@base_min}:"
|
|
28
|
+
end
|
|
29
|
+
if (@frac_sec < 10)
|
|
30
|
+
@mmss << "0#{@frac_sec}"
|
|
31
|
+
else
|
|
32
|
+
@mmss << "#{@frac_sec}"
|
|
33
|
+
end
|
|
34
|
+
if (@mmss.size > 8)
|
|
35
|
+
@mmss = @mmss[0..8]
|
|
36
|
+
end
|
|
37
|
+
else
|
|
38
|
+
@rawdata = ''
|
|
39
|
+
@seconds = invalidDistance
|
|
40
|
+
@minutes = invalidMinutes
|
|
41
|
+
@mmss = '??:??.?'
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
def scrub(raw)
|
|
48
|
+
if (raw)
|
|
49
|
+
raw.strip!
|
|
50
|
+
newStr = ''
|
|
51
|
+
raw.each_byte { | b |
|
|
52
|
+
if ((b >= 48) && (b <= 57))
|
|
53
|
+
newStr << b
|
|
54
|
+
end
|
|
55
|
+
if (b == 46)
|
|
56
|
+
newStr << b
|
|
57
|
+
end
|
|
58
|
+
}
|
|
59
|
+
return newStr
|
|
60
|
+
else
|
|
61
|
+
''
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
public
|
|
66
|
+
|
|
67
|
+
def to_s
|
|
68
|
+
"#{@mmss}"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Return a String with state values for debugging.
|
|
72
|
+
def print_string
|
|
73
|
+
"Duration: #{@rawdata} sec: #{@seconds} min: #{@minutes} mmss: #{@mmss} bm: #{@base_min} fm: #{@frac_min} fs: #{@frac_sec}"
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end # end of module
|
|
79
|
+
|