Sha256: 1e7367ce35cd95462aae6c775ab833ee877842dcc1ca3b476f9ce9c3562669c4

Contents?: true

Size: 1.61 KB

Versions: 38

Compression:

Stored size: 1.61 KB

Contents

module Vedeu

  module Geometry

    # 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.
    #
    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::Geometry::Grid.
      #
      # @param value [Fixnum]
      # @return [Vedeu::Geometry::Grid]
      def initialize(value)
        @value = value
      end

      # @see Vedeu::Geometry::DSL#columns
      def columns
        fail Vedeu::Error::OutOfRange if out_of_range?

        column * value
      end

      # @see Vedeu::Geometry::DSL#rows
      def rows
        fail Vedeu::Error::OutOfRange if out_of_range?

        row * value
      end

      protected

      # @!attribute [r] value
      # @return [Fixnum]
      attr_reader :value

      private

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

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

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

    end # Grid

  end # Geometry

end # Vedeu

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
vedeu-0.6.50 lib/vedeu/geometry/grid.rb
vedeu-0.6.49 lib/vedeu/geometry/grid.rb
vedeu-0.6.48 lib/vedeu/geometry/grid.rb
vedeu-0.6.47 lib/vedeu/geometry/grid.rb
vedeu-0.6.46 lib/vedeu/geometry/grid.rb
vedeu-0.6.45 lib/vedeu/geometry/grid.rb
vedeu-0.6.44 lib/vedeu/geometry/grid.rb
vedeu-0.6.43 lib/vedeu/geometry/grid.rb
vedeu-0.6.42 lib/vedeu/geometry/grid.rb
vedeu-0.6.41 lib/vedeu/geometry/grid.rb
vedeu-0.6.40 lib/vedeu/geometry/grid.rb
vedeu-0.6.39 lib/vedeu/geometry/grid.rb
vedeu-0.6.38 lib/vedeu/geometry/grid.rb
vedeu-0.6.37 lib/vedeu/geometry/grid.rb
vedeu-0.6.36 lib/vedeu/geometry/grid.rb
vedeu-0.6.35 lib/vedeu/geometry/grid.rb
vedeu-0.6.34 lib/vedeu/geometry/grid.rb
vedeu-0.6.33 lib/vedeu/geometry/grid.rb
vedeu-0.6.32 lib/vedeu/geometry/grid.rb
vedeu-0.6.31 lib/vedeu/geometry/grid.rb