clever_duration 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/clever_duration.gemspec +4 -4
- data/lib/clever_duration/clever_duration.rb +14 -2
- data/test/test_clever_duration.rb +8 -4
- metadata +25 -9
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/clever_duration.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{clever_duration}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ilya Sabanin"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-10-16}
|
13
13
|
s.description = %q{A tiny Ruby lib for parsing human format of time duration to numbers.}
|
14
14
|
s.email = %q{ilya.sabanin@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
s.homepage = %q{http://github.com/iSabanin/clever_duration}
|
33
33
|
s.rdoc_options = ["--charset=UTF-8"]
|
34
34
|
s.require_paths = ["lib"]
|
35
|
-
s.rubygems_version = %q{1.3.
|
35
|
+
s.rubygems_version = %q{1.3.7}
|
36
36
|
s.summary = %q{Human format time duration parsing.}
|
37
37
|
s.test_files = [
|
38
38
|
"test/helper.rb",
|
@@ -43,7 +43,7 @@ Gem::Specification.new do |s|
|
|
43
43
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
44
44
|
s.specification_version = 3
|
45
45
|
|
46
|
-
if Gem::Version.new(Gem::
|
46
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
47
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
48
48
|
else
|
49
49
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
@@ -17,6 +17,8 @@ class CleverDuration
|
|
17
17
|
def seconds
|
18
18
|
if colon_format?
|
19
19
|
regular_format_to_seconds
|
20
|
+
elsif decimal_format?
|
21
|
+
decimal_format_to_seconds
|
20
22
|
else
|
21
23
|
tokens_to_seconds
|
22
24
|
end
|
@@ -25,7 +27,11 @@ class CleverDuration
|
|
25
27
|
private
|
26
28
|
|
27
29
|
def colon_format?
|
28
|
-
!!(input =~
|
30
|
+
!!(input =~ /:/)
|
31
|
+
end
|
32
|
+
|
33
|
+
def decimal_format?
|
34
|
+
!!(input =~ /\./)
|
29
35
|
end
|
30
36
|
|
31
37
|
def tokens
|
@@ -33,9 +39,15 @@ private
|
|
33
39
|
end
|
34
40
|
|
35
41
|
def regular_format_to_seconds
|
36
|
-
hours, minutes = *input.scan(/(\d{0,2})
|
42
|
+
hours, minutes = *input.scan(/(\d{0,2}):(\d{0,2})/).flatten
|
37
43
|
(hours.to_i * 60 * 60) + (minutes.to_i * 60)
|
38
44
|
end
|
45
|
+
|
46
|
+
def decimal_format_to_seconds
|
47
|
+
hours, decimal = *input.scan(/(\d{0,2})\.(\d{0,2})/).flatten
|
48
|
+
minutes = ("0.#{decimal}".to_f * 60) / 1
|
49
|
+
(hours.to_i * 60 * 60) + (minutes * 60)
|
50
|
+
end
|
39
51
|
|
40
52
|
def tokens_to_seconds
|
41
53
|
seconds = 0
|
@@ -49,12 +49,16 @@ class CleverDurationTest < Test::Unit::TestCase
|
|
49
49
|
assert_equal 10, duration(":10").minutes
|
50
50
|
end
|
51
51
|
|
52
|
-
should "translate
|
52
|
+
should "translate decimal" do
|
53
53
|
assert_equal 3, duration("3.00").hours
|
54
54
|
assert_equal 4, duration("04.00").hours
|
55
|
-
assert_equal
|
56
|
-
assert_equal
|
57
|
-
assert_equal
|
55
|
+
assert_equal 18, duration("0.30").minutes
|
56
|
+
assert_equal 138, duration("2.30").minutes
|
57
|
+
assert_equal 2.3, duration("2.30").hours
|
58
|
+
assert_equal 6, duration(".10").minutes
|
59
|
+
assert_equal 30, duration(".50").minutes
|
60
|
+
assert_equal 1.5, duration("1.5").hours
|
61
|
+
assert_equal 90, duration("1.5").minutes
|
58
62
|
end
|
59
63
|
|
60
64
|
should "translate compounds" do
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clever_duration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 25
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Ilya Sabanin
|
@@ -9,19 +15,23 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date: 2010-
|
18
|
+
date: 2010-10-16 00:00:00 +08:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: shoulda
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
23
32
|
version: "0"
|
24
|
-
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
25
35
|
description: A tiny Ruby lib for parsing human format of time duration to numbers.
|
26
36
|
email: ilya.sabanin@gmail.com
|
27
37
|
executables: []
|
@@ -53,21 +63,27 @@ rdoc_options:
|
|
53
63
|
require_paths:
|
54
64
|
- lib
|
55
65
|
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
56
67
|
requirements:
|
57
68
|
- - ">="
|
58
69
|
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
59
73
|
version: "0"
|
60
|
-
version:
|
61
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
62
76
|
requirements:
|
63
77
|
- - ">="
|
64
78
|
- !ruby/object:Gem::Version
|
79
|
+
hash: 3
|
80
|
+
segments:
|
81
|
+
- 0
|
65
82
|
version: "0"
|
66
|
-
version:
|
67
83
|
requirements: []
|
68
84
|
|
69
85
|
rubyforge_project:
|
70
|
-
rubygems_version: 1.3.
|
86
|
+
rubygems_version: 1.3.7
|
71
87
|
signing_key:
|
72
88
|
specification_version: 3
|
73
89
|
summary: Human format time duration parsing.
|