GraphUtils 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/graphutils.rb +12 -0
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a38723353cc27a96475a0774c91d1dd01f080dca
4
- data.tar.gz: 7a51cbe06406eb18d6e7e477e1556d8187a14cf7
3
+ metadata.gz: 5546eb7bfddd04c77a046375d54cc89a198fe925
4
+ data.tar.gz: df0070edc52ea607fb840943f81ee2b80b7b3ab7
5
5
  SHA512:
6
- metadata.gz: 70f0c67605219be63d07c0050e8fbb2b32e0a3d3b482302411eb8cc0346338b7625e7bc3a6704c40b656bda5d38a70366168289bc5a12f2bb76021d6a0d47248
7
- data.tar.gz: 152a033e2b1b963e12c71c329f0c83ed6785ebc15f46a2cb2c2c3073bdcee421fbeef8ad0dd13982aa0b13ee0b93c20b2d82bc6ea3b1cf639863e1ca4ae68fac
6
+ metadata.gz: bfe48d61565dcbf68ea8e0cb25307c6f395f2365f825f507f5c3495edec075a26585a093a894601a16c4dac599ef95c3ae707440d1582489d80c59a39a6e8f7d
7
+ data.tar.gz: 328ed000ecbfdbbbafe76be2fd8deccdc3f8c010f25793ef6be4a7d46d8d4fe701dd8fee101523ad0a507d1ef25a21d533f4485c443a51526797230cb4e4338c
@@ -8,6 +8,8 @@
8
8
 
9
9
  module GraphUtils
10
10
 
11
+ # Find the coordinates of a target, returning the row and column indices as an array
12
+
11
13
  def self.find_rc(two_dimensional_array, target)
12
14
  column = nil
13
15
  row = nil
@@ -25,12 +27,16 @@ module GraphUtils
25
27
  [row, column]
26
28
  end
27
29
 
30
+ # Find a value corresponding with the given [row,column] coordinates
31
+
28
32
  def self.rc_lookup(two_dimensional_array, coordinates)
29
33
  row = coordinates[0]
30
34
  column = coordinates[1]
31
35
  two_dimensional_array[row][column]
32
36
  end
33
37
 
38
+ # Return an array of a column at a particular index.
39
+
34
40
  def self.find_column(board, column_index)
35
41
  column = []
36
42
  row_index = 0
@@ -41,6 +47,8 @@ module GraphUtils
41
47
  column
42
48
  end
43
49
 
50
+ # Returns an array of adjacent coordinates for a given set of coordinates. An options hash is included to specify an inclusive or exclusive lookup, defaulting to inclusive.
51
+
44
52
  def self.surrounding_coordinates(two_dimensional_array, coordinates, options = {} )
45
53
  raise ArgumentError.new("Must include [row,column] coordinates") unless coordinates.is_a?(Array)
46
54
  range = options[:range] || :inclusive
@@ -69,6 +77,8 @@ module GraphUtils
69
77
  values
70
78
  end
71
79
 
80
+ # Returns an array of adjacent targets for a given set of coordinates.
81
+
72
82
  def self.surrounding_coordinates_to_values(two_dimensional_array, coordinates, options = {})
73
83
  coordinates = GraphUtils.surrounding_coordinates(two_dimensional_array, coordinates, options)
74
84
 
@@ -81,6 +91,8 @@ module GraphUtils
81
91
  values
82
92
  end
83
93
 
94
+ # Deep iteration tools meant for manipulating N-D Array structures.
95
+
84
96
  def self.deepmap!(array, &block)
85
97
  array.map! do |elem|
86
98
  elem.is_a?(Array) ? deepmap!(elem, &block) : yield(elem)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: GraphUtils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marshall Hattersley