class PrintPrimesTable::Primes

@author Diego HernĂ¡n Piccinini Lagos To handle the primes numbers

Public Class Methods

new(total = DEFAULT_TOTAL) click to toggle source

@param total [Integer] the quantity of the primes collection

# File lib/print_primes_table/primes.rb, line 11
def initialize(total = DEFAULT_TOTAL)
        @total=total
        @collection = []
        fill_collection
end

Public Instance Methods

fill_collection() click to toggle source

fill the collection with primes number end when the collection.count is equal total

# File lib/print_primes_table/primes.rb, line 18
def fill_collection
        eval_number = 2
        begin
                has_divisors = false
                @collection.each do |prime|
                        if (eval_number % prime) == 0
                                has_divisors = true
                                break
                        end
                end
                # only the numbers has not divisors are primes
                @collection.push eval_number unless has_divisors
                eval_number += 1
        end until @collection.count == @total
end
list_numbers() click to toggle source

print the list of primes collection separed by tab

# File lib/print_primes_table/primes.rb, line 34
def list_numbers
        puts @collection.join("\t")
end
print_table() click to toggle source

print the table of TOTAL x TOTAL collection each coordinate contain the product