grid_generator 0.1.4 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f34702803c741397426d5272bc8e8ed3640d6a7742b17ab4e87507053375828b
4
- data.tar.gz: 5bbc7b1d5ad4274a04a15a2a5c526b295dbabe36b13f426316c8b4dc19961104
3
+ metadata.gz: 4ca39eb693f9a8ef806c69a8ad9293912e5f1a8699962939b1a92a2ae644e2cb
4
+ data.tar.gz: d59e8615cb32f345f745f99cb282d324f9253966a0e08c14c5c30868c4e6a670
5
5
  SHA512:
6
- metadata.gz: b60517eee3e40b2ab0321151a049f7912627fadc76201cb97dca08ac7799990f9660b42e1a9255f96306b4474f6591b263c75b906d520afbca0b26c3c829010c
7
- data.tar.gz: 36e148ca472c8989db168dc251a9a1145945b5465dced8e3d68ed2d86d9a7024f225a2daba6187035b6392c3ea2ca6dd6e9ceb76b4d3e2c679e8f77bfe937c55
6
+ metadata.gz: 87926ed9d36e9255069fa6b8c16fcf5e310ad283806da1fbe150c574208b32c52f5ba48159092ab0cf38fbdc39ffb1ecbe215602a89729997378c3a261e6a3a7
7
+ data.tar.gz: c3d6c72ce540b0fe1c265181a74f549a4d2c9fc87de23bf07c33f12d7d8b06e315329ddc9aaac69393c23e3c0129fd2cd0355638b95879a0736a0dbd5af4f6d4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grid_generator (0.1.4)
4
+ grid_generator (0.1.5)
5
5
  matrix (~> 0.4.2)
6
6
 
7
7
  GEM
@@ -9,7 +9,7 @@ module GridGenerator
9
9
  @units = units
10
10
  @squares = case squares
11
11
  when String
12
- FaceParser.new(squares).to_a
12
+ FaceParser.new(squares).parse
13
13
  when Array
14
14
  squares
15
15
  else
@@ -10,7 +10,7 @@ module GridGenerator
10
10
  @units = units
11
11
  @squares = case squares
12
12
  when String
13
- FaceParser.new(squares).to_a
13
+ FaceParser.new(squares).parse
14
14
  when Array
15
15
  squares
16
16
  else
@@ -1,5 +1,4 @@
1
1
  require 'matrix'
2
- require_relative '../face_parser'
3
2
  require_relative '../base_line'
4
3
 
5
4
  module GridGenerator
@@ -10,7 +9,7 @@ module GridGenerator
10
9
  @units = units
11
10
  @squares = case squares
12
11
  when String
13
- FaceParser.new(squares).to_a
12
+ squares.split('\n').map { |r| r.split(',') }
14
13
  when Array
15
14
  squares
16
15
  else
@@ -124,8 +123,7 @@ module GridGenerator
124
123
  width_unit: width_unit,
125
124
  height_unit: height_unit,
126
125
  offset_unit: offset_unit,
127
- colour: col[:colour],
128
- opacity: col[:opacity]
126
+ face: col
129
127
  ).build
130
128
  end
131
129
  end
@@ -4,12 +4,14 @@ require_relative 'units_factory'
4
4
  module GridGenerator
5
5
  module Cubic
6
6
  class SquareFactory
7
- def initialize(x:, y:, width_unit:, height_unit:, offset_unit:, colour:, opacity:)
7
+ def initialize(x:, y:, width_unit:, height_unit:, offset_unit:, face:)
8
8
  @x, @y = x, y
9
9
  @width_unit = width_unit
10
10
  @height_unit = height_unit
11
11
  @offset_unit = offset_unit
12
- @colour, @opacity = colour, opacity
12
+ face_attr = FaceParser.new(face).parse
13
+ @colour = face_attr && face_attr[:colour]
14
+ @opacity = face_attr && face_attr[:opacity]
13
15
  end
14
16
 
15
17
  attr_reader :x, :y, :width_unit, :height_unit, :offset_unit, :colour, :opacity
@@ -40,7 +42,7 @@ module GridGenerator
40
42
  end
41
43
 
42
44
  def build
43
- GridGenerator::BaseElement.new(points: points, colour: colour, opacity: opacity)
45
+ GridGenerator::BaseElement.new(points: points, colour: colour, opacity: opacity) unless colour.nil?
44
46
  end
45
47
  end
46
48
  end
@@ -12,7 +12,10 @@ module GridGenerator
12
12
  's' => '#8080ff',
13
13
  'l' => '#80ff80',
14
14
  'p' => '#800080',
15
- 'pi' => '#ff8080'
15
+ 'pi' => '#ff8080',
16
+ 'fu' => "#f0f0f0", # face up
17
+ 'ff' => "#d0d0d0", # face front
18
+ 'fr' => "#b0b0b0" # face right
16
19
  }
17
20
 
18
21
  OPACITY = {
@@ -23,19 +26,35 @@ module GridGenerator
23
26
  def initialize(string)
24
27
  @string = string
25
28
  end
29
+
30
+ def single?
31
+ @string.length == 1
32
+ end
26
33
 
27
34
  attr_reader :string
35
+
36
+ def parse
37
+ if single?
38
+ parse_char(string)
39
+ else
40
+ parse_array(string)
41
+ end
42
+ end
28
43
 
29
- def to_a
30
- string.split(/\\n/).map do |line|
44
+ def parse_char(char)
45
+ if char == '-'
46
+ nil
47
+ else
48
+ colour = COLOURS[char.downcase]
49
+ opacity = OPACITY[(/[[:upper:]]/.match(char) ? :full : :faded)]
50
+ { colour: colour, opacity: opacity }
51
+ end
52
+ end
53
+
54
+ def parse_array(str)
55
+ str.split(/\\n/).map do |line|
31
56
  line.split(',').map(&:strip).map do |col|
32
- if col == '-'
33
- nil
34
- else
35
- colour = COLOURS[col.downcase]
36
- opacity = OPACITY[(/[[:upper:]]/.match(col) ? :full : :faded)]
37
- { colour: colour, opacity: opacity }
38
- end
57
+ parse_char(col)
39
58
  end
40
59
  end
41
60
  end
@@ -10,7 +10,7 @@ module GridGenerator
10
10
  def initialize(x:, y: , units: , elements: , rotation_offset: 0, label: nil)
11
11
  @x, @y = x, y
12
12
  @units = units
13
- @elements = FaceParser.new(elements).to_a
13
+ @elements = FaceParser.new(elements).parse
14
14
  @rotation_offset = rotation_offset
15
15
  @label = label
16
16
  end
@@ -8,7 +8,7 @@ module GridGenerator
8
8
  @units = units
9
9
  @elements = case elements
10
10
  when String
11
- FaceParser.new(elements).to_a
11
+ FaceParser.new(elements).parse
12
12
  when Array
13
13
  elements
14
14
  else
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GridGenerator
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
@@ -44,8 +44,7 @@ module GridGenerator
44
44
  width_unit: width_unit,
45
45
  height_unit: height_unit,
46
46
  offset_unit: offset_unit,
47
- colour: args[:colour],
48
- opacity: args[:opacity]
47
+ face: args[:face]
49
48
  ).build
50
49
  end
51
50
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grid_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Humphreys
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-28 00:00:00.000000000 Z
11
+ date: 2023-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: matrix