Sha256: 8020750727fb9afcde8994e2850cfdd27e58bdc3986de36dfa9c6dfded13a0dd

Contents?: true

Size: 1.52 KB

Versions: 23

Compression:

Stored size: 1.52 KB

Contents

module Vedeu

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

    # @see Vedeu::DSL::Geometry#columns
    def columns
      fail Vedeu::OutOfRange,
           'Valid value between 1 and 12 inclusive.' if out_of_range?

      column * value
    end

    # @see Vedeu::DSL::Geometry#rows
    def rows
      fail Vedeu::OutOfRange,
           'Valid value between 1 and 12 inclusive.' 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 # Vedeu

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
vedeu-0.6.1 lib/vedeu/geometry/grid.rb
vedeu-0.6.0 lib/vedeu/geometry/grid.rb
vedeu-0.5.13 lib/vedeu/geometry/grid.rb
vedeu-0.5.12 lib/vedeu/geometry/grid.rb
vedeu-0.5.11 lib/vedeu/geometry/grid.rb
vedeu-0.5.10 lib/vedeu/geometry/grid.rb
vedeu-0.5.9 lib/vedeu/geometry/grid.rb
vedeu-0.5.8 lib/vedeu/geometry/grid.rb
vedeu-0.5.7 lib/vedeu/geometry/grid.rb
vedeu-0.5.6 lib/vedeu/geometry/grid.rb
vedeu-0.5.5 lib/vedeu/geometry/grid.rb
vedeu-0.5.4 lib/vedeu/geometry/grid.rb
vedeu-0.5.3 lib/vedeu/geometry/grid.rb
vedeu-0.5.2 lib/vedeu/geometry/grid.rb
vedeu-0.5.1 lib/vedeu/geometry/grid.rb
vedeu-0.5.0 lib/vedeu/geometry/grid.rb
vedeu-0.4.65 lib/vedeu/geometry/grid.rb
vedeu-0.4.64 lib/vedeu/geometry/grid.rb
vedeu-0.4.63 lib/vedeu/geometry/grid.rb
vedeu-0.4.62 lib/vedeu/geometry/grid.rb