collectable 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +9 -8
- data/lib/collectable.rb +6 -6
- data/lib/collectable/version.rb +1 -1
- data/spec/collectable_spec.rb +33 -30
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZGQ4MDQxM2RjMmExNzllOWQ4Y2M1M2YxMDQ2NjMyYjlmYWE2OTVlZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzViZTNlNjlhNGM4ODc4NTI3MTc1ZjM2NmZmMjIxMTI0YzVjNDVlYw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTJiM2JjZDZiOGRjNjg5MzA1NjNiZTJjOThmM2JlOTA2ZGJlMjc3MDI3Y2I5
|
10
|
+
NTEwMDI4MDA3ZDAzOWFhZjVlOWZmMTg3NzdjN2NmZThkOGVhZWVhNjJjYThl
|
11
|
+
MjIwODI2NmNhY2ViZGE5N2EzM2ZlOWZkZThiNDllYjgxZTgwYmM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NGY5YzdhZWFlOWI1ZWNlMmRkZjQ4NWU2YzgwMzIyZWQyODhkOTU3OTYyNmY2
|
14
|
+
NjA1NDE3ZTlkNWViMjJiY2IyMTFkN2I4ZDQ3MTg4Nzg4MGY1M2E5OTVhZWUx
|
15
|
+
ODMwNTNkNmI4MmRjZjA2M2UzOTU0MmZiY2Y3MDk4ZWEwNGQwNWM=
|
data/README.md
CHANGED
@@ -20,19 +20,19 @@ gem 'collectable'
|
|
20
20
|
```
|
21
21
|
## Basic usage ##
|
22
22
|
|
23
|
-
The short version is "include the module and define some
|
24
|
-
the long version, as it were.
|
23
|
+
The short version is "include the module and define some characteristics."
|
24
|
+
That's also the long version, as it were.
|
25
25
|
|
26
26
|
```ruby
|
27
27
|
class HairColor
|
28
28
|
include Collectable
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
characteristic :blonde
|
31
|
+
characteristic :brown
|
32
|
+
characteristic :red
|
33
|
+
characteristic :black
|
34
|
+
characteristic :purple
|
35
|
+
characteristic :tie_dye
|
36
36
|
end
|
37
37
|
```
|
38
38
|
|
@@ -55,6 +55,7 @@ Do you use git-flow? I sure do. Please base anything you do off of
|
|
55
55
|
|
56
56
|
## History ##
|
57
57
|
|
58
|
+
* 0.0.4 - Renamed "traits" to "characteristics"
|
58
59
|
* 0.0.3 - .value and .name actually added
|
59
60
|
* 0.0.2 - Renamed collected_item#val to collected_item#value
|
60
61
|
* 0.0.1 - Public release
|
data/lib/collectable.rb
CHANGED
@@ -14,17 +14,17 @@ module Collectable
|
|
14
14
|
:name
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
@
|
17
|
+
def characteristics
|
18
|
+
@characteristics ||= []
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
21
|
+
def characteristic(characteristic_name)
|
22
|
+
characteristics.push(characteristic_name.to_s.downcase)
|
23
|
+
characteristics.uniq!
|
24
24
|
end
|
25
25
|
|
26
26
|
def collected(sort_field = :name)
|
27
|
-
|
27
|
+
characteristics.each_with_index.map {|name, index|
|
28
28
|
OpenStruct.new(name: name, value: index)
|
29
29
|
}.sort {|a,b|
|
30
30
|
a.send(sort_field) <=> b.send(sort_field)
|
data/lib/collectable/version.rb
CHANGED
data/spec/collectable_spec.rb
CHANGED
@@ -5,11 +5,11 @@ class Dummy
|
|
5
5
|
include Collectable
|
6
6
|
end
|
7
7
|
|
8
|
-
class
|
8
|
+
class CharacteristicDummy
|
9
9
|
include Collectable
|
10
10
|
end
|
11
11
|
|
12
|
-
class
|
12
|
+
class CharacteristicsDummy
|
13
13
|
include Collectable
|
14
14
|
end
|
15
15
|
|
@@ -23,23 +23,23 @@ describe Collectable do
|
|
23
23
|
context 'when included' do
|
24
24
|
let(:dummy) {Dummy}
|
25
25
|
|
26
|
-
it 'knows how to define
|
27
|
-
expect(dummy).to respond_to(:
|
26
|
+
it 'knows how to define characteristics' do
|
27
|
+
expect(dummy).to respond_to(:characteristic)
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'can report its tratis' do
|
31
|
-
expect(dummy).to respond_to(:
|
31
|
+
expect(dummy).to respond_to(:characteristics)
|
32
32
|
end
|
33
33
|
|
34
|
-
it 'knows how to collect the
|
34
|
+
it 'knows how to collect the characteristics' do
|
35
35
|
expect(dummy).to respond_to(:collected)
|
36
36
|
end
|
37
37
|
|
38
|
-
it 'knows what method gets a value for a collected
|
38
|
+
it 'knows what method gets a value for a collected characteristic' do
|
39
39
|
expect(dummy).to respond_to(:value)
|
40
40
|
end
|
41
41
|
|
42
|
-
it 'knows what method gets a name for a collected
|
42
|
+
it 'knows what method gets a name for a collected characteristic' do
|
43
43
|
expect(dummy).to respond_to(:name)
|
44
44
|
end
|
45
45
|
end
|
@@ -56,42 +56,45 @@ describe Collectable do
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
describe '.
|
60
|
-
let(:
|
61
|
-
|
59
|
+
describe '.characteristic' do
|
60
|
+
let(:characteristic_dummy) {
|
61
|
+
CharacteristicDummy
|
62
62
|
}
|
63
63
|
|
64
64
|
it 'can take a symbol' do
|
65
|
-
expect {
|
65
|
+
expect {characteristic_dummy.characteristic :Blah}.not_to raise_error
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'can take a string' do
|
69
|
-
expect {
|
69
|
+
expect {characteristic_dummy.characteristic 'characteristic 2'}.
|
70
|
+
not_to raise_error
|
70
71
|
end
|
71
72
|
|
72
|
-
it 'adds a
|
73
|
-
|
74
|
-
|
75
|
-
expect(
|
73
|
+
it 'adds a characteristic to the collectable characteristics' do
|
74
|
+
new_characteristic = :New_Characteristic
|
75
|
+
characteristic_dummy.characteristic new_characteristic
|
76
|
+
expect(characteristic_dummy.characteristics).
|
77
|
+
to include(new_characteristic.to_s.downcase)
|
76
78
|
end
|
77
79
|
end
|
78
80
|
|
79
|
-
describe '.
|
80
|
-
let(:
|
81
|
-
|
81
|
+
describe '.characteristics' do
|
82
|
+
let(:characteristics_dummy) {
|
83
|
+
CharacteristicsDummy
|
82
84
|
}
|
83
85
|
|
84
|
-
let(:
|
86
|
+
let(:new_characteristic) {:new_characteristic}
|
85
87
|
|
86
88
|
it 'is an array' do
|
87
|
-
expect(
|
89
|
+
expect(characteristics_dummy.characteristics).to be_a(Array)
|
88
90
|
end
|
89
91
|
|
90
|
-
it 'contains the
|
91
|
-
expect(
|
92
|
+
it 'contains the characteristics defined by the class' do
|
93
|
+
expect(characteristics_dummy.characteristics).to be_empty
|
92
94
|
|
93
|
-
|
94
|
-
expect(
|
95
|
+
characteristics_dummy.characteristic new_characteristic
|
96
|
+
expect(characteristics_dummy.characteristics).
|
97
|
+
to include(new_characteristic.to_s.downcase)
|
95
98
|
end
|
96
99
|
end
|
97
100
|
|
@@ -104,12 +107,12 @@ describe Collectable do
|
|
104
107
|
expect(collected_dummy.collected).to be_a(Array)
|
105
108
|
end
|
106
109
|
|
107
|
-
it 'contains OpenStruct representations of the known
|
108
|
-
collected_dummy.
|
109
|
-
collected_dummy.
|
110
|
+
it 'contains OpenStruct representations of the known characteristics' do
|
111
|
+
collected_dummy.characteristic :characteristic_1
|
112
|
+
collected_dummy.characteristic :characteristic_2
|
110
113
|
|
111
114
|
expect(collected_dummy.collected.map(&:name)).
|
112
|
-
to eql(collected_dummy.
|
115
|
+
to eql(collected_dummy.characteristics.sort)
|
113
116
|
end
|
114
117
|
end
|
115
118
|
end
|