inum 4.0.3 → 5.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: 14f3242f891cb3854748f144f6128cc0197746ad
4
- data.tar.gz: 812453559ff5a224d773882da7ed4d2e3e59e01a
3
+ metadata.gz: 493bb30797a42fd6c51d030772bf00e079aee367
4
+ data.tar.gz: 699880c62844bb20bd5ef3c470eea38cbd2fb831
5
5
  SHA512:
6
- metadata.gz: 875cc3ba3269179ab9423f23a05999c13d4388c85a00b39ffd99c604ef2588f8b45a443694a6929926b8fc609d2be82988011bb59bef35fe697b47a0d24b2b4e
7
- data.tar.gz: 506d1536045e1e0b305736073468bcf6506f800008df2b562dbe0adeac0397bb9a5ff5c3749a074f9eb5bcdf5ac6462bc85dc44407e353fb027d746e23cd94ab
6
+ metadata.gz: 6267ef53da51c33f37997c01ac10872a0c5f6d94b14445ccde25cce1fdbe7ceccac38af70520af430fc81bc0593da4cb989f8173087aaf554401026d3b652ee2
7
+ data.tar.gz: 45404163209bee403e9424a4f820e0029380792a117b8f3519644b12f5ec92a26af1063a0e6ab2d5d9bc7599efae61bd007885b189cbebebfbfe12e9846b1db2
data/.gitignore CHANGED
@@ -22,7 +22,7 @@ coverage
22
22
  pkg/
23
23
  tmp/
24
24
  temp/
25
-
25
+ vendor/bundle/
26
26
 
27
27
  # IDE Projects files.
28
28
  nbproject/
@@ -6,7 +6,12 @@ rvm:
6
6
  - 1.9.3
7
7
  - 2.1.0
8
8
  - 2.2.0
9
+ - 2.3.0
9
10
  env:
10
- - ACTIVE_RECORD_VERSION=3.2.20
11
- - ACTIVE_RECORD_VERSION=4.1.7
12
- - ACTIVE_RECORD_VERSION=4.2.0
11
+ - RAILS_VERSION=3.2.20
12
+ - RAILS_VERSION=4.1.7
13
+ - RAILS_VERSION=4.2.0
14
+ matrix:
15
+ include:
16
+ - rvm: 2.3.0
17
+ env: RAILS_VERSION=5.0.0
data/Gemfile CHANGED
@@ -1,7 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- if ENV['ACTIVE_RECORD_VERSION']
4
- gem 'activerecord', ENV['ACTIVE_RECORD_VERSION']
3
+ if ENV['RAILS_VERSION']
4
+ gem 'activerecord', ENV['RAILS_VERSION']
5
+ gem 'activesupport', ENV['RAILS_VERSION']
5
6
  end
6
7
 
7
8
  # Specify your gem's dependencies in inum.gemspec
data/README.md CHANGED
@@ -39,6 +39,8 @@ How to use Enum(Inum).
39
39
  ``` ruby
40
40
  p AnimeTypes::EVANGELION.label # => :EVANGELION
41
41
  p AnimeTypes::EVANGELION.to_s # => "EVANGELION"
42
+ p AnimeTypes::EVANGELION.downcase # => "evangelion"
43
+ p AnimeTypes::EVANGELION.upcase # => "EVANGELION"
42
44
  p AnimeTypes::EVANGELION.value # => 0 (can use to_i.)
43
45
  p AnimeTypes::EVANGELION.translate # => エヴァンゲリオン (I18n.t will be called with `anime_types.evangelion`.)
44
46
 
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.name = "inum"
8
8
  spec.version = Inum::VERSION
9
9
  spec.authors = ["alfa-jpn"]
10
- spec.email = ["a.nkmr.ja@gmail.com"]
10
+ spec.email = ["alfa.jpn@gmail.com"]
11
11
  spec.description = "Inum(enumerated type of Integer) provide a java-Enum-like."
12
12
  spec.summary = "Inum(enumerated type of Integer) provide a java-Enum-like."
13
13
  spec.homepage = "https://github.com/alfa-jpn/inum"
@@ -21,9 +21,11 @@ module Inum
21
21
  # @param label [Symbol] label of Enum.
22
22
  # @param value [Integer] value of Enum.
23
23
  def initialize(label, value)
24
- @label = label
25
- @label_string = label.to_s
26
- @value = value
24
+ @label = label.freeze
25
+ @label_string = label.to_s.freeze
26
+ @label_downcase = @label_string.downcase.freeze
27
+ @label_upcase = @label_string.upcase.freeze
28
+ @value = value.freeze
27
29
 
28
30
  @underscore_class_path = self.class.name ? ActiveSupport::Inflector.underscore(self.class.name).gsub('/', '.') : ''
29
31
  @underscore_label = ActiveSupport::Inflector.underscore(label).gsub('/', '.')
@@ -59,7 +61,7 @@ module Inum
59
61
 
60
62
  # Compare object.
61
63
  #
62
- # @param [Object] parsable object.
64
+ # @param [Object] object parsable object.
63
65
  # @return [Boolean] result.
64
66
  def eql?(object)
65
67
  self.equal?(self.class.parse(object))
@@ -79,6 +81,20 @@ module Inum
79
81
  @label_string
80
82
  end
81
83
 
84
+ # Downcase label.
85
+ #
86
+ # @return [String] downcase label.
87
+ def downcase
88
+ @label_downcase
89
+ end
90
+
91
+ # Upcase label.
92
+ #
93
+ # @return [String] uppercase label.
94
+ def upcase
95
+ @label_upcase
96
+ end
97
+
82
98
  # Translate Enum to localized string.(use i18n)
83
99
  # @note find default `Namespace.Classname.EnumMember`
84
100
  #
@@ -157,12 +173,11 @@ module Inum
157
173
  if /^\d+$/.match(object)
158
174
  parse(object.to_i)
159
175
  else
160
- upcase = object.upcase
161
- find {|e| e.to_s == upcase}
176
+ downcase = object.downcase
177
+ find {|e| e.downcase == downcase}
162
178
  end
163
179
  when Symbol
164
- upcase = object.upcase
165
- find {|e| e.label == upcase}
180
+ parse(object.to_s)
166
181
  when Integer
167
182
  find {|e| e.value == object}
168
183
  when self
@@ -223,10 +238,6 @@ module Inum
223
238
  raise ArgumentError, "#{label} isn't instance of Symbol."
224
239
  end
225
240
 
226
- if labels =~ /[^A-Z\d_]/
227
- raise ArgumentError, "#{label} is wrong constant name. Label allow uppercase and digits and underscore."
228
- end
229
-
230
241
  if labels.include?(label)
231
242
  raise ArgumentError, "#{label} already exists label."
232
243
  end
@@ -1,3 +1,3 @@
1
1
  module Inum
2
- VERSION = "4.0.3"
2
+ VERSION = '5.0.0'
3
3
  end
@@ -40,12 +40,12 @@ describe Inum::Base do
40
40
  context 'When define a enum having wrong label' do
41
41
  subject do
42
42
  Class.new(Inum::Base) {
43
- define :red_bull, 0
43
+ define 'red_bull', 0
44
44
  }
45
45
  end
46
46
 
47
- it 'fail validation.' do
48
- expect { subject }.to raise_error
47
+ it 'Raise ArgumentError.' do
48
+ expect { subject }.to raise_error(ArgumentError)
49
49
  end
50
50
  end
51
51
 
@@ -57,8 +57,8 @@ describe Inum::Base do
57
57
  }
58
58
  end
59
59
 
60
- it 'fail validation.' do
61
- expect { subject }.to raise_error
60
+ it 'Raise ArgumentError.' do
61
+ expect { subject }.to raise_error(ArgumentError)
62
62
  end
63
63
  end
64
64
 
@@ -70,8 +70,8 @@ describe Inum::Base do
70
70
  }
71
71
  end
72
72
 
73
- it 'fail validation.' do
74
- expect { subject }.to raise_error
73
+ it 'Raise ArgumentError.' do
74
+ expect { subject }.to raise_error(ArgumentError)
75
75
  end
76
76
  end
77
77
  end
@@ -79,10 +79,11 @@ describe Inum::Base do
79
79
  describe 'Defined enum class' do
80
80
  before :each do
81
81
  class Anime < Inum::Base
82
- define :NYARUKO, 0
83
- define :MUROMISAN, 1
84
- define :NOURIN, 2
82
+ define :Nyaruko, 0
83
+ define :Muromisan, 1
84
+ define :Nourin, 2
85
85
  define :KMB, 3
86
+ define :Bakuon, 4
86
87
  end
87
88
  end
88
89
 
@@ -93,32 +94,32 @@ describe Inum::Base do
93
94
  describe '#<=>' do
94
95
  context 'self == other' do
95
96
  it 'Return 0.' do
96
- expect(Anime::MUROMISAN <=> 1).to eq(0)
97
+ expect(Anime::Muromisan <=> 1).to eq(0)
97
98
  end
98
99
  end
99
100
 
100
101
  context 'self < other' do
101
102
  it 'Return a negative values.' do
102
- expect(Anime::MUROMISAN <=> 2).to be < 0
103
+ expect(Anime::Muromisan <=> 2).to be < 0
103
104
  end
104
105
  end
105
106
 
106
107
  context 'self > other' do
107
108
  it 'Return a positive values.' do
108
- expect(Anime::MUROMISAN <=> 0).to be > 0
109
+ expect(Anime::Muromisan <=> 0).to be > 0
109
110
  end
110
111
  end
111
112
  end
112
113
 
113
114
  describe '#+' do
114
115
  it 'Returning value is correct.' do
115
- expect(Anime::NYARUKO + 1).to eq(Anime::MUROMISAN)
116
+ expect(Anime::Nyaruko + 1).to eq(Anime::Muromisan)
116
117
  end
117
118
  end
118
119
 
119
120
  describe '#-' do
120
121
  it 'Returning value is correct.' do
121
- expect(Anime::MUROMISAN - 1).to eq(Anime::NYARUKO)
122
+ expect(Anime::Muromisan - 1).to eq(Anime::Nyaruko)
122
123
  end
123
124
  end
124
125
 
@@ -131,7 +132,7 @@ describe Inum::Base do
131
132
 
132
133
  context 'When compare other enum' do
133
134
  it 'Return falsey value.' do
134
- expect(Anime::KMB.eql?(Anime::NYARUKO)).to be_falsey
135
+ expect(Anime::KMB.eql?(Anime::Nyaruko)).to be_falsey
135
136
  end
136
137
  end
137
138
  end
@@ -169,7 +170,19 @@ describe Inum::Base do
169
170
 
170
171
  describe '#to_s ' do
171
172
  it 'Return string.' do
172
- expect(Anime::NOURIN.to_s).to eq('NOURIN')
173
+ expect(Anime::Nourin.to_s).to eq('Nourin')
174
+ end
175
+ end
176
+
177
+ describe '#dowcase ' do
178
+ it 'Return lowercase string.' do
179
+ expect(Anime::Bakuon.downcase).to eq('bakuon')
180
+ end
181
+ end
182
+
183
+ describe '#upcase ' do
184
+ it 'Return uppercase string.' do
185
+ expect(Anime::Bakuon.upcase).to eq('BAKUON')
173
186
  end
174
187
  end
175
188
 
@@ -204,6 +217,7 @@ describe Inum::Base do
204
217
  ['t', 1],
205
218
  ['t', 2],
206
219
  ['t', 3],
220
+ ['t', 4]
207
221
  ])
208
222
  end
209
223
 
@@ -223,6 +237,7 @@ describe Inum::Base do
223
237
  ['t', 0],
224
238
  ['t', 1],
225
239
  ['t', 2],
240
+ ['t', 4]
226
241
  ])
227
242
  end
228
243
  end
@@ -230,14 +245,14 @@ describe Inum::Base do
230
245
 
231
246
  describe '.new' do
232
247
  it 'Can not create a instance of enum.' do
233
- expect{ Anime.new(:NICONICO, 2525) }.to raise_error
248
+ expect{ Anime.new(:NICONICO, 2525) }.to raise_error(NoMethodError)
234
249
  end
235
250
  end
236
251
 
237
252
  describe '.each' do
238
253
  it 'Execute block with a right order.' do
239
254
  count = 0
240
- orders = [Anime::NYARUKO, Anime::MUROMISAN, Anime::NOURIN, Anime::KMB]
255
+ orders = [Anime::Nyaruko, Anime::Muromisan, Anime::Nourin, Anime::KMB, Anime::Bakuon]
241
256
 
242
257
  Anime.each do |enum|
243
258
  expect(enum).to eq(orders[count])
@@ -248,13 +263,13 @@ describe Inum::Base do
248
263
 
249
264
  describe '.labels' do
250
265
  it 'Return array of label.' do
251
- expect(Anime.labels).to match_array([:NYARUKO, :MUROMISAN, :NOURIN, :KMB])
266
+ expect(Anime.labels).to match_array([:Nyaruko, :Muromisan, :Nourin, :KMB, :Bakuon])
252
267
  end
253
268
  end
254
269
 
255
270
  describe '.length' do
256
271
  it 'Return correct count of enum.' do
257
- expect(Anime.length).to eq(4)
272
+ expect(Anime.length).to eq(5)
258
273
  end
259
274
  end
260
275
 
@@ -263,47 +278,47 @@ describe Inum::Base do
263
278
  expect(Anime.parse(source)).to eq(destination)
264
279
  end
265
280
 
266
- let(:destination) { Anime::KMB }
281
+ let(:destination) { Anime::Bakuon }
267
282
 
268
- context 'source is string' do
269
- let(:source) { 'KMB' }
270
- it 'success.' do
283
+ context 'When source is string' do
284
+ let(:source) { 'Bakuon' }
285
+ it 'Return inum.' do
271
286
  subject
272
287
  end
273
288
  end
274
289
 
275
- context 'source is symbol' do
276
- let(:source) { :kmb }
277
- it 'success.' do
290
+ context 'When source is symbol' do
291
+ let(:source) { :bakuon }
292
+ it 'Return inum.' do
278
293
  subject
279
294
  end
280
295
  end
281
296
 
282
- context 'source is integer' do
283
- let(:source) { 3 }
297
+ context 'When source is integer' do
298
+ let(:source) { 4 }
284
299
  it 'success.' do
285
300
  subject
286
301
  end
287
302
  end
288
303
 
289
- context 'source is integer of string' do
290
- let(:source) { '3' }
291
- it 'success.' do
304
+ context 'When source is integer of string' do
305
+ let(:source) { '4' }
306
+ it 'Return inum.' do
292
307
  subject
293
308
  end
294
309
  end
295
310
 
296
- context 'source is enum' do
297
- let(:source) { Anime::KMB }
298
- it 'success.' do
311
+ context 'When source is enum' do
312
+ let(:source) { Anime::Bakuon }
313
+ it 'Return inum.' do
299
314
  subject
300
315
  end
301
316
  end
302
317
 
303
- context 'source is incorrect' do
318
+ context 'When source is incorrect' do
304
319
  let(:source) { '' }
305
320
  let(:destination) { nil }
306
- it 'return nil.' do
321
+ it 'Return inum.' do
307
322
  subject
308
323
  end
309
324
  end
@@ -315,32 +330,32 @@ describe Inum::Base do
315
330
  expect(Anime.parse!(:hoge)).to eq(returning_value)
316
331
  end
317
332
 
318
- context '#parse return enum' do
333
+ context 'When #parse return enum' do
319
334
  let(:returning_value) { Anime::KMB }
320
335
 
321
- it 'success.' do
336
+ it 'Return inum.' do
322
337
  subject
323
338
  end
324
339
  end
325
340
 
326
- context '#parse return nil' do
341
+ context 'When #parse return nil' do
327
342
  let(:returning_value) { nil }
328
343
 
329
- it 'raise error.' do
330
- expect{subject}.to raise_error
344
+ it 'Raise Inum::NotDefined.' do
345
+ expect{subject}.to raise_error(Inum::NotDefined)
331
346
  end
332
347
  end
333
348
  end
334
349
 
335
350
  describe '.to_a' do
336
351
  it 'Return array of enum.' do
337
- expect(Anime.to_a).to match_array([Anime::NYARUKO, Anime::MUROMISAN, Anime::NOURIN, Anime::KMB])
352
+ expect(Anime.to_a).to match_array([Anime::Nyaruko, Anime::Muromisan, Anime::Nourin, Anime::KMB, Anime::Bakuon])
338
353
  end
339
354
  end
340
355
 
341
356
  describe '.values' do
342
357
  it 'Return array of value.' do
343
- expect(Anime.values).to match_array([0, 1, 2, 3])
358
+ expect(Anime.values).to match_array([0, 1, 2, 3, 4])
344
359
  end
345
360
  end
346
361
  end
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: 4.0.3
4
+ version: 5.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: 2015-01-22 00:00:00.000000000 Z
11
+ date: 2016-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -124,7 +124,7 @@ dependencies:
124
124
  version: '0'
125
125
  description: Inum(enumerated type of Integer) provide a java-Enum-like.
126
126
  email:
127
- - a.nkmr.ja@gmail.com
127
+ - alfa.jpn@gmail.com
128
128
  executables: []
129
129
  extensions: []
130
130
  extra_rdoc_files: []
@@ -163,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
163
  version: '0'
164
164
  requirements: []
165
165
  rubyforge_project:
166
- rubygems_version: 2.2.2
166
+ rubygems_version: 2.5.1
167
167
  signing_key:
168
168
  specification_version: 4
169
169
  summary: Inum(enumerated type of Integer) provide a java-Enum-like.