Class: Multipri::PrimesTable

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

Defined Under Namespace

Classes: Row

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(size) ⇒ PrimesTable

Returns a new instance of PrimesTable.



29
30
31
32
# File 'lib/multipri/primes_table.rb', line 29

def initialize(size)
  @size = size
  @generated = false
end

Class Method Details

.generate(size) ⇒ Object



25
26
27
# File 'lib/multipri/primes_table.rb', line 25

def self.generate(size)
  new(size).generate
end

Instance Method Details

#generateObject



34
35
36
37
38
39
40
41
42
# File 'lib/multipri/primes_table.rb', line 34

def generate
  primes = Prime.new.first(@size)
  @row_titles = primes
  @rows = primes.map do |p|
    Row.new(p, primes.map { |q| p * q })
  end
  @generated = true
  self
end

#row_titlesObject



49
50
51
52
# File 'lib/multipri/primes_table.rb', line 49

def row_titles
  generate unless generated?
  @row_titles
end

#rowsObject



44
45
46
47
# File 'lib/multipri/primes_table.rb', line 44

def rows
  generate unless generated?
  @rows
end