inum 2.0.2 → 2.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/inum/base.rb +4 -2
- data/lib/inum/define_check_method.rb +6 -2
- data/lib/inum/version.rb +1 -1
- data/spec/inum/base_spec.rb +4 -2
- data/spec/inum/define_check_method_spec.rb +25 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb32378c9020ed24378f516a690610f0783bc7f8
|
4
|
+
data.tar.gz: b5ad93ed97447e1b339fc1b03e7647999776d615
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bde688e1396bb28dc39d2506be12b6c5172cb4f65c072c00fc8a1097964b62056968791e2b19c649ccd2aa9f2f4815428b05b444bbb1afef221e4cdf8b1d04ff
|
7
|
+
data.tar.gz: 56387c80afda5178087060b581f281b9bf4b43b10112ef1cedf0bb3070956007d0a946f3427d4e9a5cec49ab0f4c2df956765244857d382e58e619d6d20b6f2e
|
data/README.md
CHANGED
@@ -41,9 +41,9 @@ define_enum :EVANGELION # => value will auto-increment.
|
|
41
41
|
How to use Enum(Inum).
|
42
42
|
|
43
43
|
``` ruby
|
44
|
-
p AnimeType::EVANGELION
|
45
|
-
p AnimeType::EVANGELION.to_i
|
46
|
-
p AnimeType::EVANGELION.
|
44
|
+
p AnimeType::EVANGELION # => EVANGELION
|
45
|
+
p AnimeType::EVANGELION.to_i # => 0
|
46
|
+
p AnimeType::EVANGELION.translate # => エヴァンゲリオン (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.
|
data/lib/inum/base.rb
CHANGED
@@ -79,16 +79,18 @@ module Inum
|
|
79
79
|
# @note find default `Namespace.Classname.EnumMember`
|
80
80
|
#
|
81
81
|
# @return [String] localized string of Enum.
|
82
|
-
def
|
82
|
+
def translate
|
83
83
|
I18n.t(self.class.i18n_key(@label))
|
84
84
|
end
|
85
|
+
alias_method :to_t, :translate
|
85
86
|
|
86
87
|
# Enum label to underscore string.
|
87
88
|
#
|
88
89
|
# @return [String] under_score string value(label) of Enum.
|
89
|
-
def
|
90
|
+
def underscore
|
90
91
|
@underscore_label
|
91
92
|
end
|
93
|
+
alias_method :to_u, :underscore
|
92
94
|
|
93
95
|
# Execute the yield(block) with each member of enum.
|
94
96
|
#
|
@@ -16,14 +16,18 @@ module Inum
|
|
16
16
|
#
|
17
17
|
# @param variable_name [String] name of variable.
|
18
18
|
# @param enum_class [Inum::Base] class of extended Enum::EnumBase.
|
19
|
-
|
19
|
+
# @param prefix [String] prefix of define method.
|
20
|
+
def define_check_method(variable_name, enum_class, prefix = nil)
|
21
|
+
prefix = (prefix.nil?)? '' : "#{prefix}_"
|
22
|
+
|
20
23
|
self.class_eval do
|
21
24
|
enum_class::each do |enum|
|
22
|
-
define_method("#{enum.to_u}?") do
|
25
|
+
define_method("#{prefix}#{enum.to_u}?") do
|
23
26
|
enum.eql?(send(variable_name))
|
24
27
|
end
|
25
28
|
end
|
26
29
|
end
|
27
30
|
end
|
31
|
+
|
28
32
|
end
|
29
33
|
end
|
data/lib/inum/version.rb
CHANGED
data/spec/inum/base_spec.rb
CHANGED
@@ -116,11 +116,13 @@ describe Inum::Base do
|
|
116
116
|
expect( @enum::MONSTER.to_s ).to eq('MONSTER')
|
117
117
|
end
|
118
118
|
|
119
|
-
it 'to_t return localized string.' do
|
119
|
+
it 'translate and to_t return localized string.' do
|
120
|
+
expect( @enum::REDBULL.translate ).to eq('Good drink!')
|
120
121
|
expect( @enum::REDBULL.to_t ).to eq('Good drink!')
|
121
122
|
end
|
122
123
|
|
123
|
-
it 'to_u return underscore string.' do
|
124
|
+
it 'underscore and to_u return underscore string.' do
|
125
|
+
expect( @enum::REDBULL.underscore ).to eq('redbull')
|
124
126
|
expect( @enum::REDBULL.to_u ).to eq('redbull')
|
125
127
|
end
|
126
128
|
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe Inum::DefineCheckMethod do
|
5
5
|
|
6
|
-
context 'create class
|
6
|
+
context 'create class after call define_check_method' do
|
7
7
|
before(:each) do
|
8
8
|
enum = @enum = Class.new(Inum::Base) do
|
9
9
|
define_enum :REDBULL, 0
|
@@ -56,4 +56,27 @@ describe Inum::DefineCheckMethod do
|
|
56
56
|
|
57
57
|
end
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
|
+
context 'create class after call define_check_method with prefix.' do
|
61
|
+
before(:each) do
|
62
|
+
enum = @enum = Class.new(Inum::Base) do
|
63
|
+
define_enum :REDBULL, 0
|
64
|
+
define_enum :MONSTER, 1
|
65
|
+
define_enum :BURN, 2
|
66
|
+
end
|
67
|
+
|
68
|
+
@mixin = Class.new do
|
69
|
+
attr_accessor :drink
|
70
|
+
|
71
|
+
extend Inum::DefineCheckMethod
|
72
|
+
self.define_check_method(:drink, enum, 'drink_type')
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'defined comparison method.' do
|
77
|
+
expect(@mixin.method_defined?(:drink_type_redbull?)).to be_true
|
78
|
+
expect(@mixin.method_defined?(:drink_type_monster?)).to be_true
|
79
|
+
expect(@mixin.method_defined?(:drink_type_burn?)).to be_true
|
80
|
+
end
|
81
|
+
end
|
82
|
+
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: 2.0.
|
4
|
+
version: 2.0.5
|
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-
|
11
|
+
date: 2013-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|