frequency 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{frequency}
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David James"]
12
- s.date = %q{2010-03-11}
12
+ s.date = %q{2010-04-27}
13
13
  s.description = %q{Interpret strings that represent frequencies (once a day, hourly, biennially, etc.)}
14
14
  s.email = %q{djames@sunlightfoundation.com}
15
15
  s.extra_rdoc_files = [
@@ -10,36 +10,37 @@ class Frequency
10
10
  #
11
11
  # Values checked with Apple Dictionary Version 2.1.1 (80.1).
12
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
- "semiannual" => 20,
29
- "semi-annual" => 20,
30
- "semiannually" => 20,
31
- "annual" => 10,
32
- "annually" => 10,
33
- "yearly" => 10,
34
- "biennial" => 5,
35
- "biennially" => 5,
36
- "quadrennial" => 2.5,
37
- "quadrennially" => 2.5,
38
- "decade" => 1,
39
- "one time" => 0,
40
- "one-time" => 0,
41
- "other" => nil,
42
- "unknown" => nil,
13
+ "each second" => [315_360_000, true ],
14
+ "each minute" => [ 5_256_000, true ],
15
+ "hourly" => [ 87_600, true ],
16
+ "each hour" => [ 87_600, false],
17
+ "daily" => [ 3_650, true ],
18
+ "each day" => [ 3_650, false],
19
+ "weekly" => [ 520, true ],
20
+ "each week" => [ 520, false],
21
+ "fortnightly" => [ 260, true ],
22
+ "monthly" => [ 120, true ],
23
+ "each month" => [ 120, false],
24
+ "quarterly" => [ 40, true ],
25
+ "each quarter" => [ 40, false],
26
+ "biannually" => [ 20, true ],
27
+ "semiannual" => [ 20, false],
28
+ "semi-annual" => [ 20, false],
29
+ "semiannually" => [ 20, false],
30
+ "annually" => [ 10, true ],
31
+ "each year" => [ 10, false],
32
+ "yearly" => [ 10, false],
33
+ "annual" => [ 10, false],
34
+ "biennially" => [ 5, true ],
35
+ "biennial" => [ 5, false],
36
+ "quadrennially" => [ 2.5, true ],
37
+ "quadrennial" => [ 2.5, false],
38
+ "each decade" => [ 1, true ],
39
+ "decade" => [ 1, false],
40
+ "one time" => [ 0, true ],
41
+ "one-time" => [ 0, false],
42
+ "other" => [ nil, true ],
43
+ "unknown" => [ nil, true ],
43
44
  }
44
45
 
45
46
  def initialize(string)
@@ -72,17 +73,28 @@ class Frequency
72
73
 
73
74
  def per_decade
74
75
  value = FREQUENCIES[plain_text]
75
- value ? value : nil
76
+ value ? value[0] : nil
76
77
  end
77
78
 
78
79
  def per_year
79
80
  value = FREQUENCIES[plain_text]
80
- value ? (value / 10.0) : nil
81
+ value ? (value[0] / 10.0) : nil
81
82
  end
82
83
 
83
84
  def valid?
84
85
  FREQUENCIES.keys.include?(self.plain_text)
85
86
  end
87
+
88
+ # A list suitable for a drop-down list
89
+ def self.list
90
+ list = []
91
+ sortable = FREQUENCIES.select { |k, v| v[0] } # not nil
92
+ sorted = sortable.sort_by { |k, v| -v[0] }
93
+ sorted.each { |k, v| list << k if v[1] }
94
+ nil_values = FREQUENCIES.select { |k, v| v[0].nil? }.sort_by { |k, v| k }
95
+ nil_values.each { |k, v| list << k }
96
+ list
97
+ end
86
98
 
87
99
  protected
88
100
 
@@ -103,4 +115,3 @@ class Frequency
103
115
  end
104
116
 
105
117
  end
106
-
@@ -124,6 +124,29 @@ describe "Frequency" do
124
124
  end
125
125
  end
126
126
 
127
+ # ---
128
+
129
+ describe "list" do
130
+ it "should be correct" do
131
+ Frequency.list.should == [
132
+ "each second",
133
+ "each minute",
134
+ "hourly",
135
+ "daily",
136
+ "weekly",
137
+ "fortnightly",
138
+ "monthly",
139
+ "quarterly",
140
+ "biannually",
141
+ "annually",
142
+ "biennially",
143
+ "quadrennially",
144
+ "each decade",
145
+ "one time",
146
+ "other",
147
+ "unknown"
148
+ ]
149
+ end
150
+ end
151
+
127
152
  end
128
-
129
-
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 3
9
- version: 0.1.3
8
+ - 4
9
+ version: 0.1.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - David James
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-11 00:00:00 -05:00
17
+ date: 2010-04-27 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency