enumerate_it 0.7.2 → 0.7.3
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 +4 -0
- data/VERSION +1 -1
- data/enumerate_it.gemspec +2 -2
- data/lib/enumerate_it.rb +7 -2
- data/spec/enumerate_it_spec.rb +7 -0
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -173,6 +173,10 @@ located on enumerations.'enumeration_name'.'key' :
|
|
173
173
|
p.relationship_status = RelationshipStatus::DIVORCED
|
174
174
|
p.relationship_status_humanize # => 'He's divorced' => uses the provided string
|
175
175
|
|
176
|
+
You can also translate specific values:
|
177
|
+
|
178
|
+
RelationshipStatis.t(1) # => 'Casado'
|
179
|
+
|
176
180
|
== Installation
|
177
181
|
|
178
182
|
gem install enumerate_it
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.3
|
data/enumerate_it.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{enumerate_it}
|
8
|
-
s.version = "0.7.
|
8
|
+
s.version = "0.7.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["C\303\241ssio Marques"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-02-03}
|
13
13
|
s.description = %q{Have a legacy database and need some enumerations in your models to match those stupid '4 rows/2 columns' tables with foreign keys and stop doing joins just to fetch a simple description? Or maybe use some integers instead of strings as the code for each value of your enumerations? Here's EnumerateIt.}
|
14
14
|
s.email = %q{cassiommc@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/enumerate_it.rb
CHANGED
@@ -185,6 +185,11 @@ module EnumerateIt
|
|
185
185
|
enumeration.values.map {|value| [translate(value[1]), value[0]] }.sort_by { |value| value[0] }
|
186
186
|
end
|
187
187
|
|
188
|
+
def self.t(value)
|
189
|
+
target = to_a.detect { |item| item[1] == value }
|
190
|
+
target ? target[0] : value
|
191
|
+
end
|
192
|
+
|
188
193
|
def self.values_for(values)
|
189
194
|
values.map { |v| self.const_get(v.to_sym) }
|
190
195
|
end
|
@@ -193,14 +198,14 @@ module EnumerateIt
|
|
193
198
|
(list.min..list.max)
|
194
199
|
end
|
195
200
|
|
201
|
+
private
|
196
202
|
def self.translate(value)
|
197
203
|
return value unless value.is_a? Symbol
|
198
204
|
|
199
|
-
default = value.to_s.
|
205
|
+
default = value.to_s.gsub(/_/, ' ').split.map(&:capitalize).join(' ')
|
200
206
|
I18n.t("enumerations.#{self.name.underscore}.#{value.to_s.underscore}", :default => default)
|
201
207
|
end
|
202
208
|
|
203
|
-
private
|
204
209
|
def self.normalize_enumeration(values_hash)
|
205
210
|
values_hash.each_pair do |key, value|
|
206
211
|
unless value.is_a? Array
|
data/spec/enumerate_it_spec.rb
CHANGED
@@ -161,6 +161,13 @@ describe EnumerateIt do
|
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
164
|
+
describe ".t" do
|
165
|
+
it "translates a given value" do
|
166
|
+
I18n.locale = :pt
|
167
|
+
TestEnumerationWithoutArray.t('1').should == 'Primeiro Valor'
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
164
171
|
describe "#to_range" do
|
165
172
|
it "returns a Range object containing the enumeration's value interval" do
|
166
173
|
TestEnumeration.to_range.should == ("1".."3")
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enumerate_it
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 5
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 7
|
9
|
-
-
|
10
|
-
version: 0.7.
|
9
|
+
- 3
|
10
|
+
version: 0.7.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "C\xC3\xA1ssio Marques"
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-02-03 00:00:00 -02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|