Class: SweetPi::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/sweet_pi/generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(process_count = 1) ⇒ Generator

Returns a new instance of Generator.



11
12
13
14
15
16
17
# File 'lib/sweet_pi/generator.rb', line 11

def initialize(process_count = 1)
  @pi = SweetPi::PI.new
  @pi.process_count = process_count

  @from = 0
  @to = 2
end

Instance Method Details

#calcObject



29
30
31
32
# File 'lib/sweet_pi/generator.rb', line 29

def calc
  @value = @pi.calc(@to)
  self
end

#each_charObject



34
35
36
37
38
39
40
# File 'lib/sweet_pi/generator.rb', line 34

def each_char
  self.calc.to_s.each_char do |c|
    yield c
  end

  self
end

#process_count=(count) ⇒ Object



19
20
21
# File 'lib/sweet_pi/generator.rb', line 19

def process_count=(count)
  @pi.process_count = count
end

#range(from = 0, to) ⇒ Object



23
24
25
26
27
# File 'lib/sweet_pi/generator.rb', line 23

def range(from = 0, to)
  @from = from
  @to = to
  self
end

#to_sObject



42
43
44
45
46
47
48
# File 'lib/sweet_pi/generator.rb', line 42

def to_s
  from = @from + 1 if 1 <= @from
  to = @to + 2

  @value ||= Math::PI.to_d
  @value.to_s('f')[from..to]
end