timeparser 0.0.2 → 0.0.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.md +8 -4
- data/lib/timeparser.rb +1 -0
- data/lib/timeparser/core_ext.rb +5 -0
- data/lib/timeparser/version.rb +1 -1
- data/spec/lib/core_ext_spec.rb +13 -0
- data/spec/lib/timeparser_spec.rb +2 -1
- metadata +6 -3
data/Readme.md
CHANGED
@@ -3,8 +3,8 @@ Timeparser
|
|
3
3
|
|
4
4
|
Allows you to parse times from a string using a treetop grammar. It's pretty basic.
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
Examples
|
7
|
+
--------
|
8
8
|
|
9
9
|
Timeparser.parse("1h20m").to_i # => 80
|
10
10
|
Timeparser.parse("1h20m").hours # => 1
|
@@ -35,9 +35,13 @@ and then run
|
|
35
35
|
Usage
|
36
36
|
-----
|
37
37
|
|
38
|
-
Timeparser.parse('
|
38
|
+
Timeparser.parse('2hours 30minutes')
|
39
39
|
|
40
|
-
|
40
|
+
Timeparser extends String with a method called #parse_time, use it like this:
|
41
|
+
|
42
|
+
"1h30m".parse_time
|
43
|
+
|
44
|
+
each of these methods will return a Timeparser::Time instance. If you need the accumulated minutes that were parsed out of the string call the #to_i or #minutes methods.
|
41
45
|
|
42
46
|
The Time instance also knows about hours, which you can access through the #hours method. #hours takes an argument which allows you to round up the hours based on the minutes. Default is rounding down.
|
43
47
|
|
data/lib/timeparser.rb
CHANGED
data/lib/timeparser/version.rb
CHANGED
data/spec/lib/timeparser_spec.rb
CHANGED
@@ -30,6 +30,7 @@ describe Timeparser do
|
|
30
30
|
|
31
31
|
it "parses hours and minutes" do
|
32
32
|
parser.parse('1h20m').to_i.should eql 80
|
33
|
+
parser.parse('2hours 30minutes').to_i.should eql 150
|
33
34
|
end
|
34
35
|
|
35
36
|
it "parses colon notation" do
|
@@ -44,7 +45,7 @@ describe Timeparser do
|
|
44
45
|
parser.parse('').to_i.should eql 0
|
45
46
|
end
|
46
47
|
|
47
|
-
it "
|
48
|
+
it "does not parse times within a text" do
|
48
49
|
parser.parse(%Q{The movie was 1h long but the truck was 20m long.}).to_i.should eql 0
|
49
50
|
end
|
50
51
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timeparser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-09-26 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: treetop
|
16
|
-
requirement: &
|
16
|
+
requirement: &70119121251100 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70119121251100
|
25
25
|
description: Parses time information from strings.
|
26
26
|
email:
|
27
27
|
- marcel.scherf@epicteams.com
|
@@ -35,10 +35,12 @@ files:
|
|
35
35
|
- Rakefile
|
36
36
|
- Readme.md
|
37
37
|
- lib/timeparser.rb
|
38
|
+
- lib/timeparser/core_ext.rb
|
38
39
|
- lib/timeparser/parser.rb
|
39
40
|
- lib/timeparser/time.rb
|
40
41
|
- lib/timeparser/timeparsing.treetop
|
41
42
|
- lib/timeparser/version.rb
|
43
|
+
- spec/lib/core_ext_spec.rb
|
42
44
|
- spec/lib/time_spec.rb
|
43
45
|
- spec/lib/timeparser_spec.rb
|
44
46
|
- spec/spec_helper.rb
|
@@ -68,6 +70,7 @@ signing_key:
|
|
68
70
|
specification_version: 3
|
69
71
|
summary: Parses time information from strings.
|
70
72
|
test_files:
|
73
|
+
- spec/lib/core_ext_spec.rb
|
71
74
|
- spec/lib/time_spec.rb
|
72
75
|
- spec/lib/timeparser_spec.rb
|
73
76
|
- spec/spec_helper.rb
|