timeparser 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
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
- Example
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('your time information')
38
+ Timeparser.parse('2hours 30minutes')
39
39
 
40
- 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.
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
 
@@ -1,6 +1,7 @@
1
1
  require "timeparser/version"
2
2
  require "timeparser/parser"
3
3
  require "timeparser/time"
4
+ require 'timeparser/core_ext'
4
5
 
5
6
  module Timeparser
6
7
  class << self
@@ -0,0 +1,5 @@
1
+ class String
2
+ def parse_time
3
+ Timeparser.parse(self)
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Timeparser
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe String do
4
+ it "delegates to parser" do
5
+ string = "1h30m"
6
+ Timeparser.should_receive(:parse).with(string)
7
+ string.parse_time
8
+ end
9
+
10
+ it "parses time" do
11
+ "1h30m".parse_time.minutes.should eql 90
12
+ end
13
+ end
@@ -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 "parses times within a text" do
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.2
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: &70111894166920 !ruby/object:Gem::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: *70111894166920
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