frequency 0.1.0 → 0.1.1
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/VERSION +1 -1
- data/frequency.gemspec +54 -0
- data/lib/frequency.rb +31 -27
- data/spec/frequency_spec.rb +18 -0
- metadata +3 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/frequency.gemspec
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{frequency}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["David James"]
|
12
|
+
s.date = %q{2009-12-08}
|
13
|
+
s.description = %q{Interpret strings that represent frequencies (once a day, hourly, biennially, etc.)}
|
14
|
+
s.email = %q{djames@sunlightfoundation.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"frequency.gemspec",
|
27
|
+
"lib/frequency.rb",
|
28
|
+
"spec/frequency_spec.rb",
|
29
|
+
"spec/spec_helper.rb"
|
30
|
+
]
|
31
|
+
s.homepage = %q{http://github.com/djsun/frequency}
|
32
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
33
|
+
s.require_paths = ["lib"]
|
34
|
+
s.rubygems_version = %q{1.3.5}
|
35
|
+
s.summary = %q{Interpret and compare frequencies (such as hourly)}
|
36
|
+
s.test_files = [
|
37
|
+
"spec/frequency_spec.rb",
|
38
|
+
"spec/spec_helper.rb"
|
39
|
+
]
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
46
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
47
|
+
else
|
48
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
49
|
+
end
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
data/lib/frequency.rb
CHANGED
@@ -4,39 +4,43 @@ class Frequency
|
|
4
4
|
|
5
5
|
attr_accessor :plain_text
|
6
6
|
|
7
|
-
# Source: the Macintosh built-in dictionary:
|
8
7
|
# Notes:
|
9
8
|
# * biweekly is ambiguous so I left it out
|
10
9
|
# * biennially != biannually
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
"each
|
15
|
-
"each
|
16
|
-
"each
|
17
|
-
"each
|
18
|
-
"each
|
19
|
-
"each
|
20
|
-
"
|
21
|
-
"
|
22
|
-
"
|
23
|
-
"
|
24
|
-
"
|
25
|
-
"
|
26
|
-
"
|
27
|
-
"
|
28
|
-
"
|
29
|
-
"
|
30
|
-
"
|
31
|
-
"
|
32
|
-
"
|
33
|
-
"
|
34
|
-
"
|
35
|
-
"
|
10
|
+
#
|
11
|
+
# Values checked with Apple Dictionary Version 2.1.1 (80.1).
|
12
|
+
FREQUENCIES = {
|
13
|
+
"each second" => 315_360_000,
|
14
|
+
"each minute" => 5_256_000,
|
15
|
+
"each hour" => 87_600,
|
16
|
+
"each day" => 3_650,
|
17
|
+
"each week" => 520,
|
18
|
+
"each month" => 120,
|
19
|
+
"each quarter" => 40,
|
20
|
+
"each year" => 10,
|
21
|
+
"hourly" => 87_600,
|
22
|
+
"daily" => 3_650,
|
23
|
+
"weekly" => 520,
|
24
|
+
"fortnightly" => 260,
|
25
|
+
"monthly" => 120,
|
26
|
+
"quarterly" => 40,
|
27
|
+
"biannually" => 20,
|
28
|
+
"annual" => 10,
|
29
|
+
"annually" => 10,
|
30
|
+
"yearly" => 10,
|
31
|
+
"biennial" => 5,
|
32
|
+
"biennially" => 5,
|
33
|
+
"quadrennial" => 2.5,
|
34
|
+
"quadrennially" => 2.5,
|
35
|
+
"decade" => 1,
|
36
|
+
"one time" => 0,
|
37
|
+
"one-time" => 0,
|
38
|
+
"other" => nil,
|
39
|
+
"unknown" => nil,
|
36
40
|
}
|
37
41
|
|
38
42
|
def initialize(string)
|
39
|
-
self.plain_text = string
|
43
|
+
self.plain_text = string.downcase
|
40
44
|
end
|
41
45
|
|
42
46
|
def ==(other)
|
data/spec/frequency_spec.rb
CHANGED
@@ -47,6 +47,24 @@ describe "Frequency" do
|
|
47
47
|
@freq.should > Frequency.new('annually')
|
48
48
|
end
|
49
49
|
end
|
50
|
+
|
51
|
+
describe "Monthly" do
|
52
|
+
before do
|
53
|
+
@freq = Frequency.new("Monthly")
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should be valid" do
|
57
|
+
@freq.plain_text.should == "monthly"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should be valid" do
|
61
|
+
@freq.valid?.should be_true
|
62
|
+
end
|
63
|
+
|
64
|
+
it "#per_year should be correct" do
|
65
|
+
@freq.per_year.should == 12.0
|
66
|
+
end
|
67
|
+
end
|
50
68
|
|
51
69
|
describe "sometimes" do
|
52
70
|
before do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frequency
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David James
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-12-08 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- README.rdoc
|
39
39
|
- Rakefile
|
40
40
|
- VERSION
|
41
|
+
- frequency.gemspec
|
41
42
|
- lib/frequency.rb
|
42
43
|
- spec/frequency_spec.rb
|
43
44
|
- spec/spec_helper.rb
|