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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a63b0c34f9865203a5d3ee9764f348de8acbb468
4
- data.tar.gz: 5c6cf709c98159aa811f8895c8039dbf5c32b0e6
3
+ metadata.gz: cb32378c9020ed24378f516a690610f0783bc7f8
4
+ data.tar.gz: b5ad93ed97447e1b339fc1b03e7647999776d615
5
5
  SHA512:
6
- metadata.gz: df81e2a2dad6a9fe95ca1826aaf11803e65d6692157a7c5413bef666992b7165dfef23518e9363ca055120531d2c233aacaff7ca9217b75932afc2ee920a5c13
7
- data.tar.gz: 55a0bd75954e6bb4bd01cb665637dd351cee4f6ee3fc3c3a3ad2045a351ea1fe909ca4d7229ab6835d708aa8f48e3c972bd3a3b9e999ef3ecd4abf531c32f83e
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 # => EVANGELION
45
- p AnimeType::EVANGELION.to_i # => 0
46
- p AnimeType::EVANGELION.to_t # => エヴァンゲリオン (i18n find `inum.anime_type.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 to_t
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 to_u
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
- def define_check_method(variable_name, enum_class)
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
@@ -1,3 +1,3 @@
1
1
  module Inum
2
- VERSION = "2.0.2"
2
+ VERSION = "2.0.5"
3
3
  end
@@ -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 of called define_check_method' do
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
- end
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.2
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-05 00:00:00.000000000 Z
11
+ date: 2013-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler