Class: Vedeu::Grid
- Inherits:
-
Object
- Object
- Vedeu::Grid
- 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
- #value ⇒ Fixnum readonly protected
Class Method Summary collapse
Instance Method Summary collapse
- #actual_height ⇒ Fixnum private
- #actual_width ⇒ Fixnum private
-
#columns ⇒ Fixnum|OutOfRange
Returns the width in characters for the number of columns specified.
-
#height ⇒ Fixnum
(also: #row)
Returns the height of a single row in characters.
-
#initialize(value) ⇒ Grid
constructor
Returns a new instance of Vedeu::Grid.
- #out_of_range? ⇒ Boolean private
-
#rows ⇒ Fixnum|OutOfRange
Returns the height in characters for the number of rows specified.
-
#width ⇒ Fixnum
(also: #column)
Returns the width of a single column in characters.
Constructor Details
#initialize(value) ⇒ Grid
Returns a new instance of Vedeu::Grid.
40 41 42 |
# File 'lib/vedeu/geometry/grid.rb', line 40 def initialize(value) @value = value end |
Instance Attribute Details
#value ⇒ Fixnum (readonly, protected)
88 89 90 |
# File 'lib/vedeu/geometry/grid.rb', line 88 def value @value end |
Class Method Details
.columns(value) ⇒ Object
26 27 28 |
# File 'lib/vedeu/geometry/grid.rb', line 26 def self.columns(value) new(value).columns end |
.rows(value) ⇒ Object
32 33 34 |
# File 'lib/vedeu/geometry/grid.rb', line 32 def self.rows(value) new(value).rows end |
Instance Method Details
#actual_height ⇒ Fixnum (private)
93 94 95 |
# File 'lib/vedeu/geometry/grid.rb', line 93 def actual_height Vedeu::Terminal.height end |
#actual_width ⇒ Fixnum (private)
98 99 100 |
# File 'lib/vedeu/geometry/grid.rb', line 98 def actual_width Vedeu::Terminal.width end |
#columns ⇒ Fixnum|OutOfRange
Returns the width in characters for the number of columns specified.
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 |
#height ⇒ Fixnum Also known as: row
Returns the height of a single row in characters.
59 60 61 |
# File 'lib/vedeu/geometry/grid.rb', line 59 def height actual_height / 12 end |
#out_of_range? ⇒ Boolean (private)
103 104 105 |
# File 'lib/vedeu/geometry/grid.rb', line 103 def out_of_range? value < 1 || value > 12 end |
#rows ⇒ Fixnum|OutOfRange
Returns the height in characters for the number of rows specified.
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 |
#width ⇒ Fixnum Also known as: column
Returns the width of a single column in characters.
79 80 81 |
# File 'lib/vedeu/geometry/grid.rb', line 79 def width actual_width / 12 end |