inum 1.0.0 → 1.1.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: 544234bb17ff082ebab6a647cbd6de98e9537ad1
4
- data.tar.gz: 2e9ed5c46161e3fc72d8a5fa137e6f21178a97af
3
+ metadata.gz: 13fa0a53e7d738142a3ada77e6ae500e1be64b74
4
+ data.tar.gz: 0f69ba1695638ee4b501353e98da80bc8f48842c
5
5
  SHA512:
6
- metadata.gz: 33196201c228dbcb269d823423f8cd2c2e55779f615a7d47b2aab6d6d6666b68ce64e366459f02bdabb03978f3f98bf55fd059dca2a4d7dc4eaa82ae2fb40b2b
7
- data.tar.gz: ad2bf42518ac9e2c7242bf6f20ceeceb6f9b03f17ec50d265334e089e426cb2dcc25fb65728d375ee71317b23e39c726c52f8af247beeb5a3cee36d2b5c4375c
6
+ metadata.gz: b4c68d473c6edee840eb3e49e55e78c1e3cd8477f44fb8afec1afee047b4bf4c59cb881c834875701065cd04cdbecb4f29d7bb042a7f35fcdc383fc6904b4e92
7
+ data.tar.gz: 18298d6d00e8b4c06312dbc8c33e9eab8081c7c2b1a028f8babddbea6ad170892a1c3abc2ebc3dfc17210f740738fc840f806b5a4b542df032837a3dc2580857
data/README.md CHANGED
@@ -30,6 +30,12 @@ class AnimeType < Inum::Base
30
30
  end
31
31
  ```
32
32
 
33
+ If value(integer) is omitted, value(integer) is auto-incremented.
34
+
35
+ ``` ruby
36
+ define_enum :EVANGELION # => value will auto-increment.
37
+ ```
38
+
33
39
  ### Use Enum(Inum)
34
40
  How to use Enum(Inum).
35
41
 
@@ -37,11 +43,16 @@ How to use Enum(Inum).
37
43
  p AnimeType::EVANGELION # => EVANGELION
38
44
  p AnimeType::EVANGELION.to_i # => 0
39
45
 
40
- type = AnimeType::Parse(0) # parse object to instance of AnimeType.
46
+ # parse object to instance of AnimeType.
47
+ # object can use class of Symbol or String or Integer or Self.
48
+ type = AnimeType::parse(0)
41
49
  p type.equal?(AnimeType::EVANGELION) # => true (member of Enum is singleton.)
42
50
 
43
51
  p AnimeType::HARUHI.eql?('HARUHI') # => true (eql? can compare all parsable object.)
44
52
 
53
+ p AnimeType::HARUHI + 1 # => NYARUKO
54
+ p AnimeType::NYARUKO - 1 # => HARUHI
55
+
45
56
  ```
46
57
 
47
58
  - more detail is [Class::Base](http://rubydoc.info/github/alfa-jpn/inum/Inum/Base)
@@ -23,6 +23,22 @@ module Inum
23
23
  end
24
24
  @value = value
25
25
  end
26
+
27
+ # plus object.
28
+ #
29
+ # @param value [Integer] plus value.(call to_i in this method.)
30
+ # @return [Inum::Base] object after plus value.
31
+ def + (value)
32
+ self.class.parse(@value + value.to_i)
33
+ end
34
+
35
+ # minus object.
36
+ #
37
+ # @param value [Integer] plus value.(call to_i in this method.)
38
+ # @return [Inum::Base] object after plus value.
39
+ def - (value)
40
+ self.class.parse(@value - value.to_i)
41
+ end
26
42
 
27
43
  # Compare object.
28
44
  #
@@ -46,6 +62,13 @@ module Inum
46
62
  self.class.defined_enums.key(@value).to_s
47
63
  end
48
64
 
65
+ # get Enum length.
66
+ #
67
+ # @return [Integer] count of Enums.
68
+ def self.length
69
+ defined_enums.length
70
+ end
71
+
49
72
  # return array of Enums.
50
73
  #
51
74
  # @return [Array<Array<String, Integer>>] sorted array of Enums.
@@ -83,9 +106,8 @@ module Inum
83
106
  # Define Enum in called class.
84
107
  #
85
108
  # @param name [String, Symbol] name of Enum.
86
- # @param value [Integer,Fixnum] value of Enum.
87
- def self.define_enum(name, value)
88
-
109
+ # @param value [Integer,Fixnum] value of Enum.(default:autoincrement for 0.)
110
+ def self.define_enum(name, value = defined_enums.size)
89
111
  validate_enum_args!(name, value)
90
112
 
91
113
  defined_enums[name] = value
@@ -1,3 +1,3 @@
1
1
  module Inum
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -42,6 +42,18 @@ describe Inum::Base do
42
42
  }.to raise_error
43
43
  end
44
44
 
45
+ it 'define_method called without value, value is autoincrement.' do
46
+ enum = Class.new(Inum::Base) do
47
+ define_enum :REDBULL
48
+ define_enum :MONSTER
49
+ define_enum :BURN
50
+ end
51
+
52
+ expect(enum::REDBULL.to_i).to eq(0)
53
+ expect(enum::MONSTER.to_i).to eq(1)
54
+ expect(enum::BURN.to_i).to eq(2)
55
+ end
56
+
45
57
  context 'define class of extended Inum::Base,' do
46
58
  before(:each) do
47
59
  @enum = Class.new(Inum::Base) do
@@ -66,6 +78,16 @@ describe Inum::Base do
66
78
  expect( @enum::BURN.equal?(@enum::BURN )).to be_true
67
79
  end
68
80
 
81
+ it '+ return a correct Inum.' do
82
+ expect(@enum::REDBULL + 1).to eq(@enum::MONSTER)
83
+ expect(@enum::REDBULL + @enum::MONSTER).to eq(@enum::MONSTER)
84
+ end
85
+
86
+ it '- return a correct Inum.' do
87
+ expect(@enum::BURN - 1).to eq(@enum::MONSTER)
88
+ expect(@enum::BURN - @enum::MONSTER).to eq(@enum::MONSTER)
89
+ end
90
+
69
91
  it 'eql? return a correct result.' do
70
92
  expect( @enum::REDBULL.eql?(0) ).to be_true
71
93
  expect( @enum::REDBULL.eql?(1) ).to be_false
@@ -79,6 +101,10 @@ describe Inum::Base do
79
101
  expect( @enum::MONSTER.to_s ).to eq('MONSTER')
80
102
  end
81
103
 
104
+ it 'length return count of enum.' do
105
+ expect(@enum::length).to eq(3)
106
+ end
107
+
82
108
  it 'to_a return Array' do
83
109
  expect(@enum::to_a.instance_of?(Array)).to be_true
84
110
  expect(@enum::to_a.length).to eq(3)
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.0.0
4
+ version: 1.1.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-11-25 00:00:00.000000000 Z
11
+ date: 2013-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler