Class: GridGenerator::SquareOneFaceParser
- Inherits:
-
Object
- Object
- GridGenerator::SquareOneFaceParser
- Defined in:
- lib/grid_generator/square_one_face_parser.rb
Constant Summary collapse
- COLOURS =
{ 'w' => '#ffffff', 'y' => '#ffff00', 'b' => '#0000ff', 'g' => '#00ff00', 'r' => '#ff0000', 'o' => '#ff8000', 'f' => '#d0d0d0' }
- OPACITY =
{ full: 1, faded: 0.4 }
- SHAPES =
{ 'e' => :edge, 'c' => :corner, 'm' => :middle, 'f' => :middle_flipped }
- ELEMENT_DEFINITION =
/(e|c|m|f)(\d+)([a-zA-Z])/
Instance Attribute Summary collapse
-
#string ⇒ Object
readonly
Returns the value of attribute string.
Instance Method Summary collapse
- #colour(definition) ⇒ Object
-
#initialize(string) ⇒ SquareOneFaceParser
constructor
A new instance of SquareOneFaceParser.
- #offset(definition) ⇒ Object
- #opacity(definition) ⇒ Object
- #shape(definition) ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(string) ⇒ SquareOneFaceParser
Returns a new instance of SquareOneFaceParser.
27 28 29 |
# File 'lib/grid_generator/square_one_face_parser.rb', line 27 def initialize(string) @string = string end |
Instance Attribute Details
#string ⇒ Object (readonly)
Returns the value of attribute string.
31 32 33 |
# File 'lib/grid_generator/square_one_face_parser.rb', line 31 def string @string end |
Instance Method Details
#colour(definition) ⇒ Object
53 54 55 |
# File 'lib/grid_generator/square_one_face_parser.rb', line 53 def colour(definition) COLOURS[definition.downcase] end |
#offset(definition) ⇒ Object
49 50 51 |
# File 'lib/grid_generator/square_one_face_parser.rb', line 49 def offset(definition) definition.to_i end |
#opacity(definition) ⇒ Object
57 58 59 |
# File 'lib/grid_generator/square_one_face_parser.rb', line 57 def opacity(definition) OPACITY[(/[[:upper:]]/.match(definition) ? :full : :faded)] end |
#shape(definition) ⇒ Object
45 46 47 |
# File 'lib/grid_generator/square_one_face_parser.rb', line 45 def shape(definition) SHAPES[definition] end |
#to_a ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/grid_generator/square_one_face_parser.rb', line 33 def to_a string.split(',').map(&:strip).map do |col| shape_def, offset_def, colour_def = ELEMENT_DEFINITION.match(col).captures { shape: shape(shape_def), offset: offset(offset_def), colour: colour(colour_def), opacity: opacity(colour_def) } end end |