Class: Vedeu::Grid

Inherits:
Object
  • Object
show all
Defined in:
lib/vedeu/geometry/grid.rb

Overview

Augment Fixnum to calculate column width or row height in a grid-based layout.

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.

Used primarily whilst defining geometry:

width: columns(9) # (Terminal width / 12) * 9 characters wide; e.g.
                  # Terminal is 92 characters wide, maximum value is
                  # therefore 84, meaning a column is 7 characters wide.
                  # (And width is therefore 63 characters wide.)

height: rows(3)   # (Terminal height / 12) * 3 rows high; e.g.
                  # Terminal is 38 characters wide, maximum value is
                  # therefore 36, meaning a row is 3 characters tall.
                  # (And height is therefore 9 characters tall.)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Grid

Returns a new instance of Vedeu::Grid.

Parameters:

  • value (Fixnum)


40
41
42
# File 'lib/vedeu/geometry/grid.rb', line 40

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueFixnum (readonly, protected)

Returns:

  • (Fixnum)


88
89
90
# File 'lib/vedeu/geometry/grid.rb', line 88

def value
  @value
end

Class Method Details

.columns(value) ⇒ Object

See Also:



26
27
28
# File 'lib/vedeu/geometry/grid.rb', line 26

def self.columns(value)
  new(value).columns
end

.rows(value) ⇒ Object

See Also:



32
33
34
# File 'lib/vedeu/geometry/grid.rb', line 32

def self.rows(value)
  new(value).rows
end

Instance Method Details

#actual_heightFixnum (private)

Returns:

  • (Fixnum)


93
94
95
# File 'lib/vedeu/geometry/grid.rb', line 93

def actual_height
  Vedeu::Terminal.height
end

#actual_widthFixnum (private)

Returns:

  • (Fixnum)


98
99
100
# File 'lib/vedeu/geometry/grid.rb', line 98

def actual_width
  Vedeu::Terminal.width
end

#columnsFixnum|OutOfRange

Returns the width in characters for the number of columns specified.

Returns:

  • (Fixnum|OutOfRange)

Raises:

  • (OutOfRange)

    When the value parameter is not between 1 and 12 inclusive.



49
50
51
52
53
54
# File 'lib/vedeu/geometry/grid.rb', line 49

def columns
  fail OutOfRange,
       'Valid value between 1 and 12 inclusive.' if out_of_range?

  column * value
end

#heightFixnum Also known as: row

Returns the height of a single row in characters.

Returns:

  • (Fixnum)


59
60
61
# File 'lib/vedeu/geometry/grid.rb', line 59

def height
  actual_height / 12
end

#out_of_range?Boolean (private)

Returns:

  • (Boolean)


103
104
105
# File 'lib/vedeu/geometry/grid.rb', line 103

def out_of_range?
  value < 1 || value > 12
end

#rowsFixnum|OutOfRange

Returns the height in characters for the number of rows specified.

Returns:

  • (Fixnum|OutOfRange)

Raises:

  • (OutOfRange)

    When the value parameter is not between 1 and 12 inclusive.



69
70
71
72
73
74
# File 'lib/vedeu/geometry/grid.rb', line 69

def rows
  fail OutOfRange,
       'Valid value between 1 and 12 inclusive.' if out_of_range?

  row * value
end

#widthFixnum Also known as: column

Returns the width of a single column in characters.

Returns:

  • (Fixnum)


79
80
81
# File 'lib/vedeu/geometry/grid.rb', line 79

def width
  actual_width / 12
end