rduration 0.0.1 → 0.0.2

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 CHANGED
@@ -79,9 +79,15 @@ Duration
79
79
 
80
80
  ## CHANGELOG
81
81
 
82
+ * **v0.0.2 Speling And Hashify**
83
+ * Corrected spelling (thanks @czarneckiD) and killed an extraneous method.
82
84
  * **v0.0.1 Hello World**
83
85
  * Handles all of my use cases. Could be better at everything, though :).
84
86
 
87
+ ## Contributors (Thanks!)
88
+
89
+ * [czarneckiD](https://github.com/czarneckiD) fixed an odd spelling mishap.
90
+
85
91
  ## Contributing
86
92
 
87
93
  1. Fork it
@@ -1,5 +1,5 @@
1
1
  class Duration
2
- module Arithmatic
2
+ module Arithmetic
3
3
  def + other_duration
4
4
  raise StandardError.new("Cannot add #{other_duration.class} to #{self}") unless other_duration.respond_to?(:to_i)
5
5
  other_duration = other_duration.to_duration if other_duration.respond_to?(:to_duration)
@@ -1,3 +1,3 @@
1
1
  class Duration
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/duration.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  require "duration/version"
2
- require "duration/arithmatic"
2
+ require "duration/arithmetic"
3
3
 
4
4
  class Duration
5
5
  attr_accessor :raw
6
6
 
7
7
  include Comparable
8
- include Arithmatic
8
+ include Arithmetic
9
9
 
10
10
  def initialize input
11
11
  self.raw = input.to_s
@@ -41,17 +41,10 @@ class Duration
41
41
  split.zip(UNITS).reverse.map { |unit| unit.join("") }.join(" ")
42
42
  end
43
43
 
44
- def hashify string
45
- string.split(" ").inject({}) do |accum, token|
46
- _, amount, type = token.split(/([[:digit:]]+)(?=[[:alpha:]])/)
47
- accum[type] = amount.to_i
48
- accum
49
- end
50
- end
51
-
52
44
  def count input = normalize_input
53
- hashify(input).inject(0) do |accum, (unit, how_many)|
54
- accum += how_many * STANDARD_CONVERSION[unit]
45
+ input.split(" ").inject(0) do |accum, token|
46
+ _, amount, type = token.split(/([[:digit:]]+)(?=[[:alpha:]])/)
47
+ accum += STANDARD_CONVERSION[type] * amount.to_i
55
48
  accum
56
49
  end
57
50
  end
@@ -117,20 +117,15 @@ describe Duration do
117
117
  end
118
118
  end
119
119
 
120
- describe "#hashify" do
121
- it "maps a string to an easily-countable hash form" do
122
- Duration.new("42m 3s").hashify("42m 3s").should == {
123
- "m" => 42,
124
- "s" => 3
125
- }
126
- end
120
+ describe "#count" do
127
121
  normalized_inputs = {
128
- '1h 32m 07s' => { 'h' => 1, 'm' => 32, 's' => 7 },
129
- '03d 08h 11m 00s' => { 'd' => 3, 'h' => 8, 'm' => 11, 's' => 0 },
122
+ '1h 32m 07s' => 5527,
123
+ '03d 08h 11m 00s' => 288660,
124
+ '42m 3s' => 2523
130
125
  }
131
126
  normalized_inputs.each do |(input, expectation)|
132
- it "converts #{input.inspect} to #{expectation.inspect}" do
133
- Duration.new(input).hashify(input).should == expectation
127
+ it "counts the number of seconds in #{input.inspect} as #{expectation.inspect}" do
128
+ Duration.new(input).count.should == expectation
134
129
  end
135
130
  end
136
131
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rduration
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-15 00:00:00.000000000 Z
12
+ date: 2012-04-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &2156379680 !ruby/object:Gem::Requirement
16
+ requirement: &2156325920 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2156379680
24
+ version_requirements: *2156325920
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &2156379180 !ruby/object:Gem::Requirement
27
+ requirement: &2156325400 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2156379180
35
+ version_requirements: *2156325400
36
36
  description: Simple utility for parsing durations from strings and comparing them.
37
37
  Basic math is also supported.
38
38
  email:
@@ -50,7 +50,7 @@ files:
50
50
  - README.md
51
51
  - Rakefile
52
52
  - lib/duration.rb
53
- - lib/duration/arithmatic.rb
53
+ - lib/duration/arithmetic.rb
54
54
  - lib/duration/string_ext.rb
55
55
  - lib/duration/version.rb
56
56
  - rduration.gemspec