midwire_common 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ *0.1.4* (August 19, 2013)
2
+
3
+ * Added TimeTool for time string conversions
4
+
1
5
  *0.1.3* (July 29, 2013)
2
6
 
3
7
  * Fixed bug in age method
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Midwire Common Gem
2
2
 
3
- **Version: 0.1.3**
3
+ **Version: 0.1.4**
4
4
 
5
5
  A handy Ruby library for Midwire development
6
6
 
@@ -7,3 +7,4 @@ require 'midwire_common/float'
7
7
  require 'midwire_common/hash'
8
8
  require 'midwire_common/string'
9
9
  require 'midwire_common/time'
10
+ require 'midwire_common/time_tool'
@@ -0,0 +1,35 @@
1
+ module MidwireCommon
2
+
3
+ class TimeTool
4
+
5
+ # converts the given time (HH:MM:SS) to seconds
6
+ #
7
+ # +time+ the time-string
8
+ def self.time_to_seconds(time)
9
+ return -1 if time.nil? or time.strip.empty?
10
+ times = time.split(/:/).reverse
11
+ seconds = 0
12
+ for i in (0...times.length)
13
+ seconds += times[i].to_i * (60**i)
14
+ end
15
+ return seconds
16
+ end
17
+
18
+ # converts the given seconds into a time string (HH:MM:SS)
19
+ #
20
+ # +seconds+ the seconds to convert
21
+ def self.seconds_to_time(seconds)
22
+ return "unknown" if seconds.nil?
23
+ t = seconds
24
+ time = ""
25
+ 2.downto(0) { |i|
26
+ tmp = t / (60**i)
27
+ t = t - tmp * 60**i
28
+ time = time + ":" if not time.empty?
29
+ time = time + ("%02d" % tmp)
30
+ }
31
+ return time
32
+ end
33
+ end
34
+
35
+ end
@@ -1,6 +1,6 @@
1
1
  original_verbosity = $VERBOSE
2
2
  $VERBOSE = nil
3
3
  module MidwireCommon
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
6
6
  $VERBOSE = original_verbosity
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ describe MidwireCommon::TimeTool do
4
+
5
+ it "converts seconds to timestamp" do
6
+ MidwireCommon::TimeTool.seconds_to_time(92353).should == "25:39:13"
7
+ end
8
+
9
+ it "converts timestamp to seconds" do
10
+ MidwireCommon::TimeTool.time_to_seconds("25:39:13").should == 92353
11
+ end
12
+
13
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: midwire_common
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-29 00:00:00.000000000 Z
12
+ date: 2013-08-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -184,6 +184,7 @@ files:
184
184
  - lib/midwire_common/rake_tasks.rb
185
185
  - lib/midwire_common/string.rb
186
186
  - lib/midwire_common/time.rb
187
+ - lib/midwire_common/time_tool.rb
187
188
  - lib/midwire_common/version.rb
188
189
  - lib/tasks/version.rake
189
190
  - midwire_common.gemspec
@@ -196,6 +197,7 @@ files:
196
197
  - spec/lib/midwire_common/hash_spec.rb
197
198
  - spec/lib/midwire_common/string_spec.rb
198
199
  - spec/lib/midwire_common/time_spec.rb
200
+ - spec/lib/midwire_common/time_tool_spec.rb
199
201
  - spec/spec_helper.rb
200
202
  homepage: http://git-2.americadirect.net/prosup
201
203
  licenses: []
@@ -211,7 +213,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
211
213
  version: '0'
212
214
  segments:
213
215
  - 0
214
- hash: -2118496464680384868
216
+ hash: 2378234403548503770
215
217
  required_rubygems_version: !ruby/object:Gem::Requirement
216
218
  none: false
217
219
  requirements:
@@ -220,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
222
  version: '0'
221
223
  segments:
222
224
  - 0
223
- hash: -2118496464680384868
225
+ hash: 2378234403548503770
224
226
  requirements: []
225
227
  rubyforge_project:
226
228
  rubygems_version: 1.8.23
@@ -237,4 +239,5 @@ test_files:
237
239
  - spec/lib/midwire_common/hash_spec.rb
238
240
  - spec/lib/midwire_common/string_spec.rb
239
241
  - spec/lib/midwire_common/time_spec.rb
242
+ - spec/lib/midwire_common/time_tool_spec.rb
240
243
  - spec/spec_helper.rb