brianjlandau-chronic_duration 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.2
1
+ 0.9.3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{brianjlandau-chronic_duration}
8
- s.version = "0.9.2"
8
+ s.version = "0.9.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["hpoydar", "brianjlandau"]
12
- s.date = %q{2010-03-09}
12
+ s.date = %q{2010-08-17}
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/brianjlandau/chronic_duration}
30
30
  s.rdoc_options = ["--charset=UTF-8"]
31
31
  s.require_paths = ["lib"]
32
- s.rubygems_version = %q{1.3.6}
32
+ s.rubygems_version = %q{1.3.7}
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"
@@ -39,7 +39,7 @@ Gem::Specification.new do |s|
39
39
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
40
40
  s.specification_version = 3
41
41
 
42
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
42
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
43
  s.add_development_dependency(%q<rspec>, [">= 0"])
44
44
  else
45
45
  s.add_dependency(%q<rspec>, [">= 0"])
@@ -110,14 +110,23 @@ private
110
110
  end
111
111
 
112
112
  def calculate_from_words(string)
113
- val = 0
113
+ val = nil
114
114
  words = string.split(' ')
115
115
  words.each_with_index do |v, k|
116
116
  if v =~ float_matcher
117
- val += (convert_to_number(v) * duration_units_seconds_multiplier(words[k + 1] || 'seconds'))
117
+ word_val = (convert_to_number(v) * duration_units_seconds_multiplier(words[k + 1] || 'seconds'))
118
+ if val
119
+ val += word_val
120
+ else
121
+ val = word_val
122
+ end
118
123
  end
119
124
  end
120
- val
125
+ if !words.empty? && val.nil? && ChronicDuration.raise_exceptions
126
+ raise DurationParseError, "An invalid string was being passed to parsed."
127
+ else
128
+ val
129
+ end
121
130
  end
122
131
 
123
132
  def cleanup(string)
@@ -33,6 +33,12 @@ describe ChronicDuration, '.parse' do
33
33
  ChronicDuration.raise_exceptions = false
34
34
  end
35
35
 
36
+ it "should raise an exception if the string can't be parsed and @@raise_exceptions is set to true" do
37
+ ChronicDuration.raise_exceptions = true
38
+ lambda { ChronicDuration.parse('Day') }.should raise_exception(ChronicDuration::DurationParseError)
39
+ ChronicDuration.raise_exceptions = false
40
+ end
41
+
36
42
  it "should return a float if seconds are in decimals" do
37
43
  ChronicDuration.parse('12 mins 3.141 seconds').is_a?(Float).should be_true
38
44
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brianjlandau-chronic_duration
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 61
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 9
8
- - 2
9
- version: 0.9.2
9
+ - 3
10
+ version: 0.9.3
10
11
  platform: ruby
11
12
  authors:
12
13
  - hpoydar
@@ -15,16 +16,18 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-03-09 00:00:00 -05:00
19
+ date: 2010-08-17 00:00:00 -04:00
19
20
  default_executable:
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
22
23
  name: rspec
23
24
  prerelease: false
24
25
  requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
25
27
  requirements:
26
28
  - - ">="
27
29
  - !ruby/object:Gem::Version
30
+ hash: 3
28
31
  segments:
29
32
  - 0
30
33
  version: "0"
@@ -58,23 +61,27 @@ rdoc_options:
58
61
  require_paths:
59
62
  - lib
60
63
  required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
61
65
  requirements:
62
66
  - - ">="
63
67
  - !ruby/object:Gem::Version
68
+ hash: 3
64
69
  segments:
65
70
  - 0
66
71
  version: "0"
67
72
  required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
68
74
  requirements:
69
75
  - - ">="
70
76
  - !ruby/object:Gem::Version
77
+ hash: 3
71
78
  segments:
72
79
  - 0
73
80
  version: "0"
74
81
  requirements: []
75
82
 
76
83
  rubyforge_project:
77
- rubygems_version: 1.3.6
84
+ rubygems_version: 1.3.7
78
85
  signing_key:
79
86
  specification_version: 3
80
87
  summary: A Ruby natural language parser for elapsed time