Sha256: 9d7b7a78f56edd5f505c1812bfdbd9aa5c814c7e2ced28bd9d75f665b97f1072

Contents?: true

Size: 1.3 KB

Versions: 3

Compression:

Stored size: 1.3 KB

Contents

require_relative '../face_parser'

module GridGenerator
  module RediCube 
    class Grid
      def initialize(x:, y:, units: , elements: )
        @x, @y = x, y
        @units = units
        @elements = case elements
                    when String
                      FaceParser.new(elements).parse
                    when Array
                      elements
                    else
                      raise ArgumentError, "elements must be array or string"
                    end
      end

      attr_reader :x, :y, :units, :elements

      def to_svg
        output = ''

        element_shapes.each { |element| output += element.to_svg if element }

        output
      end

      private

      def build_element(row_num, col_num, data)
        if data
          element_factory_class.new(
            grid_x: x,
            grid_y: y,
            row_num: row_num,
            col_num: col_num,
            units: units,
            colour: data[:colour],
            opacity: data[:opacity]
          ).build
        else
          nil
        end
      end

      def element_shapes
        elements.each_with_index.map do |row, row_num|
          row.each_with_index.map do |col, col_num|
            build_element(row_num, col_num, col)
          end
        end.flatten.compact
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
grid_generator-0.6.7 lib/grid_generator/redi_cube/grid.rb
grid_generator-0.6.6 lib/grid_generator/redi_cube/grid.rb
grid_generator-0.6.5 lib/grid_generator/redi_cube/grid.rb