chronic_duration 0.9.5 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -50,7 +50,7 @@ ChronicDuration.raise_exceptions can be set to true to raise exceptions when the
50
50
 
51
51
  == Contributors
52
52
 
53
- brianjlandau, jduff, olauzon, roboman
53
+ brianjlandau, jduff, olauzon, roboman, ianlevesque
54
54
 
55
55
  == TODO
56
56
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.5
1
+ 0.9.6
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{chronic_duration}
8
- s.version = "0.9.5"
8
+ s.version = "0.9.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["hpoydar"]
12
- s.date = %q{2011-05-20}
12
+ s.date = %q{2011-06-04}
13
13
  s.description = %q{A simple Ruby natural language parser for elapsed time. (For example, 4 hours and 30 minutes, 6 minutes 4 seconds, 3 days, etc.) Returns all results in seconds. Will return an integer unless you get tricky and need a float. (4 minutes and 13.47 seconds, for example.) The reverse can also be performed via the output method.}
14
14
  s.email = %q{hpoydar@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -29,7 +29,7 @@ Gem::Specification.new do |s|
29
29
  s.homepage = %q{http://github.com/hpoydar/chronic_duration}
30
30
  s.licenses = ["MIT"]
31
31
  s.require_paths = ["lib"]
32
- s.rubygems_version = %q{1.6.2}
32
+ s.rubygems_version = %q{1.5.2}
33
33
  s.summary = %q{A Ruby natural language parser for elapsed time}
34
34
  s.test_files = [
35
35
  "spec/chronic_duration_spec.rb"
@@ -18,8 +18,8 @@ module ChronicDuration
18
18
  # Given a string representation of elapsed time,
19
19
  # return an integer (or float, if fractions of a
20
20
  # second are input)
21
- def parse(string)
22
- result = calculate_from_words(cleanup(string))
21
+ def parse(string, opts = {})
22
+ result = calculate_from_words(cleanup(string), opts)
23
23
  result == 0 ? nil : result
24
24
  end
25
25
 
@@ -113,12 +113,12 @@ private
113
113
  res
114
114
  end
115
115
 
116
- def calculate_from_words(string)
116
+ def calculate_from_words(string, opts)
117
117
  val = 0
118
118
  words = string.split(' ')
119
119
  words.each_with_index do |v, k|
120
120
  if v =~ float_matcher
121
- val += (convert_to_number(v) * duration_units_seconds_multiplier(words[k + 1] || 'seconds'))
121
+ val += (convert_to_number(v) * duration_units_seconds_multiplier(words[k + 1] || (opts[:default_unit] || 'seconds')))
122
122
  end
123
123
  end
124
124
  val
@@ -43,6 +43,10 @@ describe ChronicDuration, '.parse' do
43
43
  ChronicDuration.parse('12 mins 3 seconds').is_a?(Integer).should be_true
44
44
  end
45
45
 
46
+ it "should be able to parse minutes by default" do
47
+ ChronicDuration.parse('5', :default_unit => "minutes").should == 300
48
+ end
49
+
46
50
  @exemplars.each do |k, v|
47
51
  it "should properly parse a duration like #{k}" do
48
52
  ChronicDuration.parse(k).should == v
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: chronic_duration
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.9.5
5
+ version: 0.9.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - hpoydar
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-20 00:00:00 -04:00
13
+ date: 2011-06-04 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -100,7 +100,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
102
102
  - !ruby/object:Gem::Version
103
- hash: -1174044456786451054
103
+ hash: 2762452318022251891
104
104
  segments:
105
105
  - 0
106
106
  version: "0"
@@ -113,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  requirements: []
114
114
 
115
115
  rubyforge_project:
116
- rubygems_version: 1.6.2
116
+ rubygems_version: 1.5.2
117
117
  signing_key:
118
118
  specification_version: 3
119
119
  summary: A Ruby natural language parser for elapsed time