Class: PrimeNumbers::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/prime-numbers.rb

Instance Method Summary collapse

Constructor Details

#initialize(algorithm_strategy) ⇒ Generator

Returns a new instance of Generator.



7
8
9
# File 'lib/prime-numbers.rb', line 7

def initialize algorithm_strategy
  @algorithm = Algorithm.with_strategy(algorithm_strategy)
end

Instance Method Details

#generate(a, b) ⇒ Object



11
12
13
14
# File 'lib/prime-numbers.rb', line 11

def generate a, b
  a,b = range_sanitizer(a,b)[0], range_sanitizer(a,b)[1]
  @algorithm.generate(a,b)
end

#is_prime?(number) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/prime-numbers.rb', line 16

def is_prime? number
  @algorithm.is_prime? number
end