Class: ForChrisLib::Framed

Inherits:
Object
  • Object
show all
Defined in:
lib/chris_lib/for_chris_lib.rb

Overview

Lightweight helper that keeps table data and headers together.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(header, rows) ⇒ Framed

Returns a new instance of Framed.

Parameters:

  • header (Array<String>)
  • rows (Array<Array>)


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

#hshObject (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

#headerArray<String>

Returns:

  • (Array<String>)


171
172
173
# File 'lib/chris_lib/for_chris_lib.rb', line 171

def header
  hsh[:header]
end

#rowsArray<Array>

Returns:

  • (Array<Array>)


176
177
178
# File 'lib/chris_lib/for_chris_lib.rb', line 176

def rows
  hsh[:rows]
end