enumerate_it 0.7.15 → 0.7.16

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.rdoc CHANGED
@@ -78,6 +78,18 @@ This will create some nice stuff:
78
78
 
79
79
  RelationshipStatus.key_for(RelationshioStatus::MARRIED) # :married
80
80
 
81
+ * You can iterate over the list of the enumeration's values:
82
+
83
+ RelationshipStatus.each_value { |value| # ... }
84
+
85
+ * You can iterate over the list of the enumeration's translations:
86
+
87
+ RelationshipStatus.each_translation { |translation| # ... }
88
+
89
+ * You can ask for the enumeration's length:
90
+
91
+ RelationshipStatus.length # 4
92
+
81
93
  * You can manipulate the hash used to create the enumeration:
82
94
 
83
95
  RelationshipStatus.enumeration # returns the exact hash used to define the enumeration
data/lib/enumerate_it.rb CHANGED
@@ -74,6 +74,14 @@
74
74
  #
75
75
  # RelationshipStatus.value_for("MARRIED") # 2
76
76
  #
77
+ # You can iterate over the list of the enumeration's values:
78
+ #
79
+ # RelationshipStatus.each_value { |value| # ... }
80
+ #
81
+ # You can iterate over the list of the enumeration's translations:
82
+ #
83
+ # RelationshipStatus.each_translation { |translation| # ... }
84
+ #
77
85
  # You can retrieve the symbol used to declare a specific enumeration value:
78
86
  #
79
87
  # RelationshipStatus.key_for(RelationshioStatus::MARRIED) # :married
@@ -226,6 +234,18 @@ module EnumerateIt
226
234
  enumeration.values.map {|value| [translate(value[1]), value[0]] }.sort_by { |value| value[0] }
227
235
  end
228
236
 
237
+ def self.length
238
+ list.length
239
+ end
240
+
241
+ def self.each_translation
242
+ each_value { |value| yield t(value) }
243
+ end
244
+
245
+ def self.each_value
246
+ list.each { |value| yield value }
247
+ end
248
+
229
249
  def self.to_json
230
250
  enumeration.values.collect {|value| { :value => value[0], :label => translate(value[1]) } }.to_json
231
251
  end
@@ -295,7 +315,6 @@ module EnumerateIt
295
315
  end
296
316
 
297
317
  private
298
-
299
318
  def store_enumeration(klass, attribute)
300
319
  enumerations[attribute] = klass
301
320
  end
@@ -1,3 +1,3 @@
1
1
  module EnumerateIt
2
- VERSION = "0.7.15"
2
+ VERSION = "0.7.16"
3
3
  end
@@ -230,6 +230,32 @@ describe EnumerateIt::Base do
230
230
  }
231
231
  end
232
232
 
233
+ describe ".length" do
234
+ it "returns the length of the enumeration" do
235
+ TestEnumeration.length.should == 3
236
+ end
237
+ end
238
+
239
+ describe ".each_translation" do
240
+ it "yields each enumeration's value translation" do
241
+ translations = []
242
+ TestEnumeration.each_translation do |translation|
243
+ translations << translation
244
+ end
245
+ translations.should == ["Hey, I am 1!", "Hey, I am 2!", "Hey, I am 3!"]
246
+ end
247
+ end
248
+
249
+ describe ".each_value" do
250
+ it "yields each enumeration's value" do
251
+ values = []
252
+ TestEnumeration.each_value do |value|
253
+ values << value
254
+ end
255
+ values.should == TestEnumeration.list
256
+ end
257
+ end
258
+
233
259
  describe ".to_a" do
234
260
  it "returns an array with the values and human representations" do
235
261
  TestEnumeration.to_a.should == [['Hey, I am 1!', '1'], ['Hey, I am 2!', '2'], ['Hey, I am 3!', '3']]
@@ -265,7 +291,7 @@ describe EnumerateIt::Base do
265
291
  end
266
292
  end
267
293
 
268
- describe "#to_range" do
294
+ describe ".to_range" do
269
295
  it "returns a Range object containing the enumeration's value interval" do
270
296
  TestEnumeration.to_range.should == ("1".."3")
271
297
  end
@@ -277,13 +303,13 @@ describe EnumerateIt::Base do
277
303
  end
278
304
  end
279
305
 
280
- describe "#value_for" do
306
+ describe ".value_for" do
281
307
  it "returns the enumeration's value" do
282
308
  TestEnumeration.value_for("VALUE_1").should == TestEnumeration::VALUE_1
283
309
  end
284
310
  end
285
311
 
286
- describe "#key_for" do
312
+ describe ".key_for" do
287
313
  it "returns the key for the given value inside the enumeration" do
288
314
  TestEnumeration.key_for(TestEnumeration::VALUE_1).should == :value_1
289
315
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enumerate_it
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.15
4
+ version: 0.7.16
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-01 00:00:00.000000000 Z
12
+ date: 2012-07-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport