Class: ForChrisLib::Framed
- Inherits:
-
Object
- Object
- ForChrisLib::Framed
- Defined in:
- lib/chris_lib/for_chris_lib.rb
Overview
Lightweight helper that keeps table data and headers together.
Instance Attribute Summary collapse
-
#hsh ⇒ Object
readonly
Returns the value of attribute hsh.
Instance Method Summary collapse
- #header ⇒ Array<String>
-
#initialize(header, rows) ⇒ Framed
constructor
A new instance of Framed.
- #rows ⇒ Array<Array>
Constructor Details
#initialize(header, rows) ⇒ Framed
Returns a new instance of Framed.
155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/chris_lib/for_chris_lib.rb', line 155 def initialize(header, rows) raise 'header must be an array' unless header.is_a?(Array) raise 'rows must be an array' unless rows.is_a?(Array) raise 'header cannot be empty' if header.empty? @hsh = { header: header, rows: rows } rows.each_with_index do |row, index| raise "row #{index} must respond to #size" unless row.respond_to?(:size) next if row.size == header.size raise "row #{index} size not equal to header size" end end |
Instance Attribute Details
#hsh ⇒ Object (readonly)
Returns the value of attribute hsh.
151 152 153 |
# File 'lib/chris_lib/for_chris_lib.rb', line 151 def hsh @hsh end |
Instance Method Details
#header ⇒ Array<String>
171 172 173 |
# File 'lib/chris_lib/for_chris_lib.rb', line 171 def header hsh[:header] end |
#rows ⇒ Array<Array>
176 177 178 |
# File 'lib/chris_lib/for_chris_lib.rb', line 176 def rows hsh[:rows] end |