Sha256: 9f3862bee24272c8ba131b63fe77c6388405cffe92d7f7aead247f6387bd9d5c

Contents?: true

Size: 1.63 KB

Versions: 16

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true

module Vedeu

  module Geometries

    # The grid system splits the terminal height and width into 12
    # equal parts, by dividing the available height and width by 12.
    # If the terminal height or width is not a multiple of 12, then
    # Grid chooses the maximum value which will fit.
    #
    # @api private
    #
    class Grid

      # @see #initialize
      # @see #columns
      def self.columns(value)
        new(value).columns
      end

      # @see #initialize
      # @see #rows
      def self.rows(value)
        new(value).rows
      end

      # Returns a new instance of Vedeu::Geometries::Grid.
      #
      # @param value [Fixnum]
      # @return [Vedeu::Geometries::Grid]
      def initialize(value)
        @value = value
      end

      # @see Vedeu::Geometries::DSL#columns
      def columns
        column * value
      end

      # @see Vedeu::Geometries::DSL#rows
      def rows
        row * value
      end

      private

      # Returns the width of a single column in characters.
      #
      # @return [Fixnum]
      def column
        Vedeu.width / 12
      end

      # Returns a boolean indicating whether the value is out of
      # range.
      #
      # @return [Boolean]
      def out_of_range?(v)
        v < 1 || v > 12
      end

      # Returns the height of a single row in characters.
      #
      # @return [Fixnum]
      def row
        Vedeu.height / 12
      end

      # @macro raise_out_of_range
      # @return [Fixnum]
      def value
        raise Vedeu::Error::OutOfRange if out_of_range?(@value)

        @value
      end

    end # Grid

  end # Geometries

end # Vedeu

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
vedeu-0.8.32 lib/vedeu/geometries/dsl/grid.rb
vedeu-0.8.31 lib/vedeu/geometries/dsl/grid.rb
vedeu-0.8.30 lib/vedeu/geometries/dsl/grid.rb
vedeu-0.8.29 lib/vedeu/geometries/dsl/grid.rb
vedeu-0.8.28 lib/vedeu/geometries/dsl/grid.rb
vedeu-0.8.27 lib/vedeu/geometries/dsl/grid.rb
vedeu-0.8.26 lib/vedeu/geometries/dsl/grid.rb
vedeu-0.8.25 lib/vedeu/geometries/dsl/grid.rb
vedeu-0.8.24 lib/vedeu/geometries/dsl/grid.rb
vedeu-0.8.23 lib/vedeu/geometries/dsl/grid.rb
vedeu-0.8.22 lib/vedeu/geometries/dsl/grid.rb
vedeu-0.8.21 lib/vedeu/geometries/dsl/grid.rb
vedeu-0.8.20 lib/vedeu/geometries/dsl/grid.rb
vedeu-0.8.19 lib/vedeu/geometries/dsl/grid.rb
vedeu-0.8.18 lib/vedeu/geometries/dsl/grid.rb
vedeu-0.8.17 lib/vedeu/geometries/dsl/grid.rb