Class: Matrix

Inherits:
Object
  • Object
show all
Defined in:
lib/primes_table/matrix.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Matrix

Returns a new instance of Matrix.



6
7
8
9
10
11
12
# File 'lib/primes_table/matrix.rb', line 6

def initialize(args)
  rows = header(args[:rows])
  columns = header(args[:columns])
  @table = load_table(rows, columns)
  @rows_header = rows
  @columns_header = columns
end

Instance Attribute Details

#columns_headerObject

Returns the value of attribute columns_header.



4
5
6
# File 'lib/primes_table/matrix.rb', line 4

def columns_header
  @columns_header
end

#rows_headerObject

Returns the value of attribute rows_header.



4
5
6
# File 'lib/primes_table/matrix.rb', line 4

def rows_header
  @rows_header
end

#tableObject

Returns the value of attribute table.



4
5
6
# File 'lib/primes_table/matrix.rb', line 4

def table
  @table
end

Instance Method Details



14
15
16
17
18
19
20
# File 'lib/primes_table/matrix.rb', line 14

def print
  distance = last_value.to_s.length
  puts format_columns_header(distance)
  table.each_with_index do |row, index|
    puts format_rows(row, index, distance)
  end
end