crafting_table 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.asc +11 -0
  3. data.tar.gz.asc +11 -0
  4. data/.gitignore +0 -0
  5. data/Gemfile +3 -0
  6. data/Gemfile.lock +41 -0
  7. data/LICENSE +14 -0
  8. data/Rakefile +0 -0
  9. data/crafting_table.gemspec +19 -0
  10. data/data/items/thermal_expansion.yml +64 -0
  11. data/data/items/vanilla.yml +1152 -0
  12. data/data/recipes/thermal_expansion.yml +97 -0
  13. data/data/recipes/vanilla.yml +25 -0
  14. data/data/test/items/vanilla.yml +1149 -0
  15. data/data/test/recipes/vanilla.yml +25 -0
  16. data/examples/interactive_table.rb +98 -0
  17. data/features/item_differentiation.feature +18 -0
  18. data/features/loading_items.feature +10 -0
  19. data/features/resolving_recipes.feature +26 -0
  20. data/features/searching_items.feature +83 -0
  21. data/features/searching_recipes.feature +42 -0
  22. data/features/step_definitions/item_manager_steps.rb +88 -0
  23. data/features/step_definitions/item_steps.rb +23 -0
  24. data/features/step_definitions/recipe_manager_steps.rb +42 -0
  25. data/features/support/env.rb +29 -0
  26. data/lib/crafting_table.rb +19 -0
  27. data/lib/crafting_table/item.rb +61 -0
  28. data/lib/crafting_table/item_manager.rb +171 -0
  29. data/lib/crafting_table/recipe.rb +36 -0
  30. data/lib/crafting_table/recipe_manager.rb +216 -0
  31. data/lib/crafting_table/search/damage_search.rb +51 -0
  32. data/lib/crafting_table/search/fuzzy_name_search.rb +39 -0
  33. data/lib/crafting_table/search/input_search.rb +47 -0
  34. data/lib/crafting_table/search/item_id_search.rb +51 -0
  35. data/lib/crafting_table/search/name_search.rb +71 -0
  36. data/lib/crafting_table/search/output_search.rb +47 -0
  37. data/lib/crafting_table/search/search_builder.rb +85 -0
  38. data/spec/crafting_table/item_manager_spec.rb +421 -0
  39. data/spec/crafting_table/item_spec.rb +67 -0
  40. data/spec/crafting_table/recipe_manager_spec.rb +353 -0
  41. data/spec/crafting_table/recipe_spec.rb +25 -0
  42. data/spec/crafting_table/search/search_builder.rb +105 -0
  43. data/spec/crafting_table/search/search_spec.rb +383 -0
  44. data/spec/spec_helper.rb +6 -0
  45. metadata +145 -0
  46. metadata.gz.asc +11 -0
@@ -0,0 +1,383 @@
1
+ #coding: utf-8
2
+
3
+ require_relative '../../spec_helper'
4
+
5
+ module CraftingTable
6
+
7
+ module Search
8
+
9
+ describe NameSearch do
10
+
11
+ describe '#initialize' do
12
+
13
+ it 'should set the appropriate instance variables' do
14
+ search = NameSearch.new('Gold Ore', case_sensitive: false)
15
+ expect(search.name).to eq 'Gold Ore'
16
+ expect(search).to_not be_case_sensitive
17
+ end
18
+
19
+ it 'should be exact' do
20
+ search = NameSearch.new('Gold Ore', exact: true, case_sensitive: false)
21
+ expect(search).to be_exact
22
+ end
23
+
24
+ it 'should default to case-sensitive matching' do
25
+ search = NameSearch.new('Foobar')
26
+ expect(search).to be_case_sensitive
27
+ end
28
+
29
+ end
30
+
31
+ describe '#apply_to' do
32
+ let(:item_log) { Item.new('Log', 17) }
33
+ let(:item_gold_ore) { Item.new('Gold Ore', 14) }
34
+ let(:item_iron_ore) { Item.new('Iron Ore', 15) }
35
+ let(:items) { [item_log, item_gold_ore, item_iron_ore] }
36
+
37
+ context 'with case sensitivity' do
38
+ let(:args) { { case_sensitive: true } }
39
+
40
+ it 'should return items with matching case' do
41
+ expect(NameSearch.new('Gold Ore', args).apply_to(items)).to eq [item_gold_ore]
42
+ expect(NameSearch.new('Log', args).apply_to(items)).to eq [item_log]
43
+ end
44
+
45
+ it 'should not return items where the case does not match' do
46
+ expect(NameSearch.new('gold ore', args).apply_to(items)).to be_empty
47
+ end
48
+
49
+ end
50
+
51
+ context 'with case-insensitivity' do
52
+ let(:args) { { case_sensitive: false } }
53
+
54
+ it 'should return items no matter their case' do
55
+ expect(NameSearch.new('Gold Ore', args).apply_to(items)).to eq [item_gold_ore]
56
+ expect(NameSearch.new('GOld OrE', args).apply_to(items)).to eq [item_gold_ore]
57
+ expect(NameSearch.new('gold ore', args).apply_to(items)).to eq [item_gold_ore]
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+
64
+ describe '#==' do
65
+
66
+ it 'should return true if name and case sensitivity match' do
67
+ expect(NameSearch.new('Gold Ore', case_sensitive: true)).to eq NameSearch.new('Gold Ore', case_sensitive: true)
68
+ expect(NameSearch.new('Wood', case_sensitive: false)).to eq NameSearch.new('Wood', case_sensitive: false)
69
+ end
70
+
71
+ it "should return false if name or case sensitivity don't match" do
72
+ expect(NameSearch.new('Stone', case_sensitive: true)).not_to eq NameSearch.new('Stone', case_sensitive: false)
73
+ expect(NameSearch.new('Stone', case_sensitive: true)).not_to eq NameSearch.new('Stoone', case_sensitive: true)
74
+ end
75
+
76
+ end
77
+
78
+ end
79
+
80
+ describe FuzzyNameSearch do
81
+
82
+ describe '#initialize' do
83
+
84
+ it 'should set the appropriate instance variables' do
85
+ search = FuzzyNameSearch.new('Gold Ore', case_sensitive: false)
86
+ expect(search.name).to eq 'Gold Ore'
87
+ expect(search).to_not be_case_sensitive
88
+ end
89
+
90
+ it 'should not be exact' do
91
+ search = FuzzyNameSearch.new('Gold Ore', case_sensitive: false)
92
+ expect(search).to_not be_exact
93
+ end
94
+
95
+ it 'should default to case-sensitive matching' do
96
+ search = FuzzyNameSearch.new('Foobar')
97
+ expect(search).to be_case_sensitive
98
+ end
99
+
100
+ end
101
+
102
+ describe '#apply_to' do
103
+ let(:item_log) { Item.new('Log', 17) }
104
+ let(:item_gold_ore) { Item.new('Gold Ore', 14) }
105
+ let(:item_iron_ore) { Item.new('Iron Ore', 15) }
106
+ let(:items) { [item_log, item_gold_ore, item_iron_ore] }
107
+
108
+ context 'with case sensitivity' do
109
+ let(:args) { { case_sensitive: true } }
110
+
111
+ it 'should return items with matching case' do
112
+ expect(FuzzyNameSearch.new('Gold', args).apply_to(items)).to eq [item_gold_ore]
113
+ expect(FuzzyNameSearch.new('og', args).apply_to(items)).to eq [item_log]
114
+ end
115
+
116
+ it 'should not return items where the case does not match' do
117
+ expect(FuzzyNameSearch.new('gold', args).apply_to(items)).to be_empty
118
+ end
119
+
120
+ end
121
+
122
+ context 'with case-insensitivity' do
123
+ let(:args) { { case_sensitive: false } }
124
+
125
+ it 'should return items no matter their case' do
126
+ expect(FuzzyNameSearch.new('Gold', args).apply_to(items)).to eq [item_gold_ore]
127
+ expect(FuzzyNameSearch.new('GOld', args).apply_to(items)).to eq [item_gold_ore]
128
+ expect(FuzzyNameSearch.new('gold', args).apply_to(items)).to eq [item_gold_ore]
129
+ end
130
+
131
+ end
132
+
133
+ end
134
+
135
+ describe '#==' do
136
+
137
+ it 'should return true if name and case sensitivity match' do
138
+ expect(FuzzyNameSearch.new('Gold Ore', case_sensitive: true)).to eq FuzzyNameSearch.new('Gold Ore', case_sensitive: true)
139
+ expect(FuzzyNameSearch.new('Wood', case_sensitive: false)).to eq FuzzyNameSearch.new('Wood', case_sensitive: false)
140
+ end
141
+
142
+ it "should return false if name or case sensitivity don't match" do
143
+ expect(FuzzyNameSearch.new('Stone', case_sensitive: true)).not_to eq FuzzyNameSearch.new('Stone', case_sensitive: false)
144
+ expect(FuzzyNameSearch.new('Stone', case_sensitive: true)).not_to eq FuzzyNameSearch.new('Stoone', case_sensitive: false)
145
+ end
146
+
147
+ end
148
+
149
+ end
150
+
151
+ describe DamageSearch do
152
+
153
+ describe '#initialize' do
154
+
155
+ it 'should set the appropriate instance variables' do
156
+ expect(DamageSearch.new(1).damage_value).to eq 1
157
+ expect(DamageSearch.new(2..4).damage_value).to eq 2..4
158
+ end
159
+
160
+ end
161
+
162
+ describe '#apply_to' do
163
+ let(:item_log) { Item.new('Log', 17) }
164
+ let(:item_gold_ore) { Item.new('Gold Ore', 14) }
165
+ let(:item_iron_ore) { Item.new('Iron Ore', 15) }
166
+
167
+ let(:item_wood_oak) { Item.new('Oak Wood', 17, 0) }
168
+ let(:item_wood_spruce) { Item.new('Spruce Wood', 17, 1) }
169
+ let(:item_wood_birch) { Item.new('Birch Wood', 17, 2) }
170
+ let(:item_wood_jungle) { Item.new('Jungle Wood', 17, 3) }
171
+
172
+ let(:items) { [item_wood_oak, item_wood_spruce,
173
+ item_wood_birch, item_wood_jungle] }
174
+
175
+ context 'with an integer' do
176
+
177
+ it 'should return items with matching damage value' do
178
+ expect(DamageSearch.new(3).apply_to(items)).to eq [item_wood_jungle]
179
+ expect(DamageSearch.new(1).apply_to(items)).to eq [item_wood_spruce]
180
+ end
181
+
182
+ end
183
+
184
+ context 'with a range or array' do
185
+
186
+ it 'should return items the damage value of which is included in the range or array' do
187
+ expect(DamageSearch.new(1..3).apply_to(items)).to eq [item_wood_spruce,
188
+ item_wood_birch,
189
+ item_wood_jungle]
190
+ expect(DamageSearch.new([1, 3]).apply_to(items)).to eq [item_wood_spruce,
191
+ item_wood_jungle]
192
+ end
193
+
194
+ end
195
+
196
+ end
197
+
198
+ describe '#==' do
199
+
200
+ it 'should return true if the damage value matches' do
201
+ expect(DamageSearch.new(1)).to eq DamageSearch.new(1)
202
+ expect(DamageSearch.new(3..7)).to eq DamageSearch.new(3..7)
203
+ end
204
+
205
+ it 'should return false if the damage value does not match' do
206
+ expect(DamageSearch.new(4)).not_to eq DamageSearch.new(3)
207
+ end
208
+
209
+ end
210
+
211
+ end
212
+
213
+ describe ItemIDSearch do
214
+
215
+ describe '#initialize' do
216
+
217
+ it 'should set the appropriate instance variables' do
218
+ expect(ItemIDSearch.new(1).item_id).to eq 1
219
+ expect(ItemIDSearch.new(2..4).item_id).to eq 2..4
220
+ end
221
+
222
+ end
223
+
224
+ describe '#apply_to' do
225
+ let(:item_log) { Item.new('Log', 17) }
226
+ let(:item_stone) { Item.new('Stone', 1) }
227
+ let(:item_gold_ore) { Item.new('Gold Ore', 14) }
228
+ let(:item_iron_ore) { Item.new('Iron Ore', 15) }
229
+
230
+ let(:item_wood_oak) { Item.new('Oak Wood', 17, 0) }
231
+ let(:item_wood_spruce) { Item.new('Spruce Wood', 17, 1) }
232
+ let(:item_wood_birch) { Item.new('Birch Wood', 17, 2) }
233
+ let(:item_wood_jungle) { Item.new('Jungle Wood', 17, 3) }
234
+
235
+ let(:items) { [item_stone,
236
+ item_gold_ore, item_iron_ore,
237
+ item_wood_oak, item_wood_spruce,
238
+ item_wood_birch, item_wood_jungle] }
239
+
240
+ context 'with an integer' do
241
+
242
+ it 'should return items with matching item ID' do
243
+ expect(ItemIDSearch.new(17).apply_to(items)).to eq [item_wood_oak,
244
+ item_wood_spruce,
245
+ item_wood_birch,
246
+ item_wood_jungle]
247
+
248
+ expect(ItemIDSearch.new(14).apply_to(items)).to eq [item_gold_ore]
249
+ end
250
+
251
+ end
252
+
253
+ context 'with a range or array' do
254
+
255
+ it 'should return items the item ID of which is included in the range or array' do
256
+ expect(ItemIDSearch.new(14..15).apply_to(items)).to eq [item_gold_ore,
257
+ item_iron_ore]
258
+
259
+ expect(ItemIDSearch.new([1, 14]).apply_to(items)).to eq [item_stone,
260
+ item_gold_ore]
261
+ end
262
+
263
+ end
264
+
265
+ describe '#==' do
266
+
267
+ it 'should return true if the item ID matches' do
268
+ expect(ItemIDSearch.new(1)).to eq ItemIDSearch.new(1)
269
+ expect(ItemIDSearch.new(3..7)).to eq ItemIDSearch.new(3..7)
270
+ end
271
+
272
+ it 'should return false if the item ID does not match' do
273
+ expect(ItemIDSearch.new(4)).not_to eq ItemIDSearch.new(3)
274
+ end
275
+
276
+ end
277
+
278
+ end
279
+
280
+ end
281
+
282
+ describe InputSearch do
283
+ let(:item_log) { Item.new('Log', 17) }
284
+
285
+ let(:item_iron_ore) { Item.new('Iron Ore', 15) }
286
+
287
+ let(:item_wood_oak) { Item.new('Oak Wood', 17, 0) }
288
+
289
+ let(:item_planks) { Item.new('Wood Planks', 5) }
290
+ let(:item_coal) { Item.new('Coal', 263) }
291
+ let(:item_stick) { Item.new('Stick', 280) }
292
+ let(:item_torch) { Item.new('Torch', 50) }
293
+
294
+ let(:recipe_planks) { Recipe.new('Wood Planks', { item_wood_oak => 1 }, { item_planks => 4 }) }
295
+ let(:recipe_sticks) { Recipe.new('Sticks', { item_planks => 2 }, { item_stick => 4 }) }
296
+ let(:recipe_torch) { Recipe.new('Torch', { item_stick => 1, item_coal => 1 }, { item_torch => 4 }) }
297
+
298
+ let(:recipes) { [recipe_planks, recipe_sticks, recipe_torch] }
299
+
300
+ describe '#initialize' do
301
+
302
+ it 'should set the approrpiate instance variables' do
303
+ expect(InputSearch.new(item_iron_ore).item).to eq item_iron_ore
304
+ end
305
+
306
+ end
307
+
308
+ describe '#apply_to' do
309
+
310
+ it 'should return recipes which have the item as input' do
311
+ search = InputSearch.new(item_coal)
312
+ expect(search.apply_to(recipes)).to eq [recipe_torch]
313
+ end
314
+
315
+ end
316
+
317
+ describe '#==' do
318
+
319
+ it 'should return true if the item is equal' do
320
+ expect(InputSearch.new(item_iron_ore)).to eq InputSearch.new(Item.new('Iron Ore', 15))
321
+ end
322
+
323
+ it 'should return false if the item is not equal' do
324
+ expect(InputSearch.new(item_torch)).not_to eq InputSearch.new(Item.new('Stone', 1))
325
+ end
326
+
327
+ end
328
+
329
+ end
330
+
331
+ describe OutputSearch do
332
+ let(:item_log) { Item.new('Log', 17) }
333
+
334
+ let(:item_iron_ore) { Item.new('Iron Ore', 15) }
335
+
336
+ let(:item_wood_oak) { Item.new('Oak Wood', 17, 0) }
337
+
338
+ let(:item_planks) { Item.new('Wood Planks', 5) }
339
+ let(:item_coal) { Item.new('Coal', 263) }
340
+ let(:item_stick) { Item.new('Stick', 280) }
341
+ let(:item_torch) { Item.new('Torch', 50) }
342
+
343
+ let(:recipe_planks) { Recipe.new('Wood Planks', { item_wood_oak => 1 }, { item_planks => 4 }) }
344
+ let(:recipe_sticks) { Recipe.new('Sticks', { item_planks => 2 }, { item_stick => 4 }) }
345
+ let(:recipe_torch) { Recipe.new('Torch', { item_stick => 1, item_coal => 1 }, { item_torch => 4 }) }
346
+ let(:recipes) { [recipe_planks, recipe_sticks, recipe_torch] }
347
+
348
+ describe '#initialize' do
349
+
350
+ it 'should set the appropriate instance variables' do
351
+ expect(OutputSearch.new(item_torch).item).to eq item_torch
352
+ end
353
+
354
+ end
355
+
356
+ describe '#apply_to' do
357
+
358
+ it 'should return recipes which have the item as output' do
359
+ search = OutputSearch.new(item_torch)
360
+ expect(search.apply_to(recipes)).to eq [recipe_torch]
361
+ end
362
+
363
+ end
364
+ pp
365
+ describe '#==' do
366
+
367
+ it 'should return true if the item is equal' do
368
+ expect(OutputSearch.new(item_torch)).to eq OutputSearch.new(Item.new('Torch', 50))
369
+ end
370
+ pp
371
+ it 'should return false if the item is not equal' do
372
+ expect(OutputSearch.new(item_torch)).not_to eq OutputSearch.new(Item.new('Stone', 1))
373
+ end
374
+
375
+ end
376
+
377
+ end
378
+
379
+ end
380
+
381
+ end
382
+
383
+
@@ -0,0 +1,6 @@
1
+ #coding: utf-8
2
+
3
+ require_relative '../lib/crafting_table'
4
+
5
+ ITEM_FILE = 'data/test/items/vanilla.yml'
6
+ RECIPE_FILE = 'data/test/recipes/vanilla.yml'
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: crafting_table
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Senn
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: cucumber
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: yard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Crafting assistant for Minecraft.
56
+ email:
57
+ - morrolan@morrolan.ch
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - LICENSE
66
+ - Rakefile
67
+ - crafting_table.gemspec
68
+ - data/items/thermal_expansion.yml
69
+ - data/items/vanilla.yml
70
+ - data/recipes/thermal_expansion.yml
71
+ - data/recipes/vanilla.yml
72
+ - data/test/items/vanilla.yml
73
+ - data/test/recipes/vanilla.yml
74
+ - examples/interactive_table.rb
75
+ - features/item_differentiation.feature
76
+ - features/loading_items.feature
77
+ - features/resolving_recipes.feature
78
+ - features/searching_items.feature
79
+ - features/searching_recipes.feature
80
+ - features/step_definitions/item_manager_steps.rb
81
+ - features/step_definitions/item_steps.rb
82
+ - features/step_definitions/recipe_manager_steps.rb
83
+ - features/support/env.rb
84
+ - lib/crafting_table.rb
85
+ - lib/crafting_table/item.rb
86
+ - lib/crafting_table/item_manager.rb
87
+ - lib/crafting_table/recipe.rb
88
+ - lib/crafting_table/recipe_manager.rb
89
+ - lib/crafting_table/search/damage_search.rb
90
+ - lib/crafting_table/search/fuzzy_name_search.rb
91
+ - lib/crafting_table/search/input_search.rb
92
+ - lib/crafting_table/search/item_id_search.rb
93
+ - lib/crafting_table/search/name_search.rb
94
+ - lib/crafting_table/search/output_search.rb
95
+ - lib/crafting_table/search/search_builder.rb
96
+ - spec/crafting_table/item_manager_spec.rb
97
+ - spec/crafting_table/item_spec.rb
98
+ - spec/crafting_table/recipe_manager_spec.rb
99
+ - spec/crafting_table/recipe_spec.rb
100
+ - spec/crafting_table/search/search_builder.rb
101
+ - spec/crafting_table/search/search_spec.rb
102
+ - spec/spec_helper.rb
103
+ homepage: https://bitbucket.org/Lavode/crafting-table
104
+ licenses:
105
+ - Apache 2.0
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.0.3
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: A library allowing to calculate the required amount of resources to craft
127
+ item(s) in Minecraft.
128
+ test_files:
129
+ - features/item_differentiation.feature
130
+ - features/loading_items.feature
131
+ - features/resolving_recipes.feature
132
+ - features/searching_items.feature
133
+ - features/searching_recipes.feature
134
+ - features/step_definitions/item_manager_steps.rb
135
+ - features/step_definitions/item_steps.rb
136
+ - features/step_definitions/recipe_manager_steps.rb
137
+ - features/support/env.rb
138
+ - spec/crafting_table/item_manager_spec.rb
139
+ - spec/crafting_table/item_spec.rb
140
+ - spec/crafting_table/recipe_manager_spec.rb
141
+ - spec/crafting_table/recipe_spec.rb
142
+ - spec/crafting_table/search/search_builder.rb
143
+ - spec/crafting_table/search/search_spec.rb
144
+ - spec/spec_helper.rb
145
+ has_rdoc: