board_game_grid 0.1.5 → 0.1.9
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/board_game_grid.rb +3 -1
- data/lib/board_game_grid/square.rb +5 -1
- data/lib/board_game_grid/square_set.rb +26 -0
- data/lib/board_game_grid/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4a8a71192d04a29fc52392b43d2cf529345183506d75cba8cf2b48fa19a79e1
|
4
|
+
data.tar.gz: b1106c165058b32667a21168498c08026a3cdd39ecd6b2100df2dc20ec01c278
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a9dc8424d4fdb0ab80ff86eb8441a8759375a042c48293d8fd03dc647aaf8a2de769feca7824f2800c239fa97d37145558676371af5022adfd9e5dfef978b2d
|
7
|
+
data.tar.gz: 01f681727b848101dde180858fff484a06890aa7134b79418d6d94e6a774a6b2d0f5e8f0e3235017473a6252f2b39348929c1d9e3e1dd3a565444a76bbb0b258
|
data/.gitignore
CHANGED
data/lib/board_game_grid.rb
CHANGED
@@ -74,8 +74,12 @@ module BoardGameGrid
|
|
74
74
|
def attribute_match?(attribute, value)
|
75
75
|
hash_obj_matcher = lambda do |obj, k, v|
|
76
76
|
value = obj.send(k)
|
77
|
-
if
|
77
|
+
if v.is_a?(Hash) && !value.nil?
|
78
78
|
v.all? { |k2,v2| hash_obj_matcher.call(value, k2, v2) }
|
79
|
+
elsif v.is_a?(Array) && !value.is_a?(Array)
|
80
|
+
v.include?(value)
|
81
|
+
elsif v.is_a?(Proc)
|
82
|
+
v.call(value)
|
79
83
|
else
|
80
84
|
value == v
|
81
85
|
end
|
@@ -289,6 +289,32 @@ module BoardGameGrid
|
|
289
289
|
select { |square| Vector.new(origin, square).dx.abs == distance }
|
290
290
|
end
|
291
291
|
|
292
|
+
# Find all squares in the same rank as square
|
293
|
+
#
|
294
|
+
# @param [Square] square
|
295
|
+
# the originating square
|
296
|
+
#
|
297
|
+
# @return [SquareSet]
|
298
|
+
# ==== Example:
|
299
|
+
# # Get all squares in the same rank as square_a
|
300
|
+
# square_set.same_rank(square_a)
|
301
|
+
def same_rank(origin)
|
302
|
+
select { |square| square.y == origin.y }
|
303
|
+
end
|
304
|
+
|
305
|
+
# Find all squares in the same file as square
|
306
|
+
#
|
307
|
+
# @param [Square] square
|
308
|
+
# the originating square
|
309
|
+
#
|
310
|
+
# @return [SquareSet]
|
311
|
+
# ==== Example:
|
312
|
+
# # Get all squares in the same file as square_a
|
313
|
+
# square_set.same_file(square_a)
|
314
|
+
def same_file(origin)
|
315
|
+
select { |square| square.x == origin.x }
|
316
|
+
end
|
317
|
+
|
292
318
|
# Find all squares orthogonal from square
|
293
319
|
#
|
294
320
|
# @param [Square] square
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: board_game_grid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Humphreys
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|