Class: SweetPi::Generator
- Inherits:
-
Object
- Object
- SweetPi::Generator
- Defined in:
- lib/sweet_pi/generator.rb
Instance Method Summary collapse
- #calc ⇒ Object
- #each_char ⇒ Object
-
#initialize(process_count = 1) ⇒ Generator
constructor
A new instance of Generator.
- #process_count=(count) ⇒ Object
- #range(from = 0, to) ⇒ Object
- #to_s ⇒ Object
Constructor Details
Instance Method Details
#calc ⇒ Object
29 30 31 32 |
# File 'lib/sweet_pi/generator.rb', line 29 def calc @value = @pi.calc(@to) self end |
#each_char ⇒ Object
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_s ⇒ Object
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 |