inum 1.3.7 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2444048eeca560efb532eaa19664c90b7d2d04a7
4
- data.tar.gz: 54da67d9bda64b6f6f27e39daee963dc32f75df1
3
+ metadata.gz: 0a6e4aafb92b4720071dd774230f494aa12c262f
4
+ data.tar.gz: 8e4bbf13d8e57b1797429a4e90aa87eaf861981e
5
5
  SHA512:
6
- metadata.gz: daba5f2276fe14a2d9690fbdb7f46b50b4c13b3701d9bef80148bdfeaa1048f6d213859f9d461ded0bf8ec407656c3378c208c6df4298cfbb821f21f2ec18385
7
- data.tar.gz: 9b54db93b5e6f141fbe6de234f40feb5647cce4aeeba79072c3c8e0e00bdf0ea45027debd7ab790466becd8f74260e09ff9b636a9f451b9ac74f4ddd72df9e4c
6
+ metadata.gz: df2f30c61d0f50a81aa9828c7acb0c1b87bd788aaf28a3b3d6aa1ce30bb1e1be6fcecd95a59ae18bab13307fc4259341e719952dcf4b4a4223e5f3b2b4df9c25
7
+ data.tar.gz: 6e1bb7185dfd184393c41ec1a4c6fc142ee6b311738abbbcfa097c1253d6a71001ad3a9d11d3b7627af6a5f983d2a1a35c218d97bff1c8d51f20b34cc3365276
data/README.md CHANGED
@@ -43,7 +43,7 @@ How to use Enum(Inum).
43
43
  ``` ruby
44
44
  p AnimeType::EVANGELION # => EVANGELION
45
45
  p AnimeType::EVANGELION.to_i # => 0
46
- p AnimeType::EVANGELION.to_t # => エヴァンゲリオン (i18n find `anime_type.evangelion`.)
46
+ p AnimeType::EVANGELION.to_t # => エヴァンゲリオン (i18n find `inum.anime_type.evangelion`.)
47
47
 
48
48
  # parse object to instance of AnimeType.
49
49
  # object can use class of Symbol or String or Integer or Self.
@@ -96,16 +96,27 @@ p anime.haruhi? # => true
96
96
 
97
97
  ### Localize(i18n)
98
98
  to_t methods localize enum by i18n.
99
- default i18n key is name_space.class_name.enum_member_label.
99
+ default i18n key is inum.{name_space}.{class_name}.{enum_member_label}.
100
100
  If change default, Override i18n_key class method.
101
101
 
102
102
  ``` ruby
103
103
  # default i18n_key.
104
104
  def self.i18n_key(label)
105
- Inum::Utils::underscore("#{self.name}::#{label}")
105
+ Inum::Utils::underscore("inum::#{self.name}::#{label}")
106
106
  end
107
107
  ```
108
108
 
109
+ example
110
+
111
+ ``` yaml
112
+ ja:
113
+ inum:
114
+ anime_type:
115
+ evangelion: 'エヴァンゲリオン'
116
+ haruhi: 'ハルヒ'
117
+ nyaruko: '這いよれ!ニャル子さん'
118
+ ```
119
+
109
120
  ## API DOCUMENT
110
121
 
111
122
  - [Documentation for alfa-jpn/Inum(master)](http://rubydoc.info/github/alfa-jpn/inum/frames)
data/lib/inum/base.rb CHANGED
@@ -166,9 +166,11 @@ module Inum
166
166
  self.const_set(label, new(label, value))
167
167
  end
168
168
 
169
- # get hash of :DEFINED_ENUMS.
169
+ # get hash of @defined_enums.
170
+ #
171
+ # @return [Hash] hash of defined enums.
170
172
  def self.defined_enums
171
- self.const_get(:DEFINED_ENUMS)
173
+ @defined_enums
172
174
  end
173
175
 
174
176
  # get key for I18n.t method.
@@ -178,13 +180,13 @@ module Inum
178
180
  # @return [String] key for I18n.t method.
179
181
  # @abstract If change key from the default.
180
182
  def self.i18n_key(label)
181
- Inum::Utils::underscore("#{self.name}::#{label}")
183
+ Inum::Utils::underscore("inum::#{self.name}::#{label}")
182
184
  end
183
185
 
184
186
  # call after inherited.
185
187
  # @note Define hash of :DEFINED_ENUMS in child.
186
188
  def self.inherited(child)
187
- child.const_set(:DEFINED_ENUMS, Hash.new)
189
+ child.instance_variable_set(:@defined_enums, Hash.new)
188
190
  end
189
191
 
190
192
  # Validate enum args, and raise exception.
@@ -196,10 +198,6 @@ module Inum
196
198
  raise ArgumentError, "The label(#{label}!) isn't instance of Symbol."
197
199
  end
198
200
 
199
- if label == :DEFINED_ENUMS
200
- raise ArgumentError, "The label(#{label}!) is keyword."
201
- end
202
-
203
201
  if defined_enums.has_key?(label)
204
202
  raise ArgumentError, "The label(#{label}!) already exists!!"
205
203
  end
@@ -18,9 +18,9 @@ module Inum
18
18
  # @param enum_class [Inum::Base] class of extended Enum::EnumBase.
19
19
  def define_check_method(variable_name, enum_class)
20
20
  self.class_eval do
21
- enum_class::DEFINED_ENUMS.each_key do |enum_name|
22
- define_method("#{Inum::Utils::underscore(enum_name)}?") do
23
- enum_class::parse(enum_name).eql?(send(variable_name))
21
+ enum_class::each do |enum|
22
+ define_method("#{enum.to_u}?") do
23
+ enum.eql?(send(variable_name))
24
24
  end
25
25
  end
26
26
  end
data/lib/inum/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Inum
2
- VERSION = "1.3.7"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -54,7 +54,7 @@ describe Inum::Base do
54
54
  end
55
55
 
56
56
  it 'i18n.t called when call define_enum.' do
57
- I18n.should_receive(:t).with('hoge.redbull')
57
+ I18n.should_receive(:t).with('inum.hoge.redbull')
58
58
 
59
59
  class Hoge < Inum::Base
60
60
  define_enum :REDBULL
@@ -79,7 +79,12 @@ describe Inum::Base do
79
79
  @enum2 = Class.new(Inum::Base) do
80
80
  define_enum :REDBULL, 0
81
81
  end
82
- expect( @enum::DEFINED_ENUMS.equal?(@enum2::DEFINED_ENUMS) ).to be_false
82
+
83
+ defined_enum_inst = @enum.instance_variable_get(:@defined_enums)
84
+ defined_enum_inst2 = @enum2.instance_variable_get(:@defined_enums)
85
+
86
+ expect( defined_enum_inst.eql?(defined_enum_inst2) ).to be_false
87
+ expect( defined_enum_inst.equal?(defined_enum_inst2) ).to be_false
83
88
  end
84
89
 
85
90
  it 'A enum instance is equal instance.' do
@@ -164,9 +169,12 @@ describe Inum::Base do
164
169
  end
165
170
 
166
171
  it 'to_h return Hash' do
172
+ defined_enum_inst = @enum.instance_variable_get(:@defined_enums)
173
+
167
174
  expect(@enum::to_h.instance_of?(Hash)).to be_true
168
- expect(@enum::to_h.eql?(@enum::DEFINED_ENUMS)).to be_true
169
- expect(@enum::to_h.equal?(@enum::DEFINED_ENUMS)).to be_false
175
+
176
+ expect(@enum::to_h.eql?(defined_enum_inst)).to be_true
177
+ expect(@enum::to_h.equal?(defined_enum_inst)).to be_false
170
178
  end
171
179
 
172
180
  it 'parse return instance from string.' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inum
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.7
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - alfa-jpn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-01 00:00:00.000000000 Z
11
+ date: 2013-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler