Class: Charosc::Generator
- Inherits:
-
Object
- Object
- Charosc::Generator
- Defined in:
- lib/charosc/generator.rb
Instance Attribute Summary collapse
-
#chars ⇒ Object
readonly
Returns the value of attribute chars.
-
#depth ⇒ Object
Returns the value of attribute depth.
-
#mod_bottom ⇒ Object
Returns the value of attribute mod_bottom.
-
#mod_enabled ⇒ Object
Returns the value of attribute mod_enabled.
-
#mod_inc ⇒ Object
Returns the value of attribute mod_inc.
-
#mod_top ⇒ Object
Returns the value of attribute mod_top.
-
#oscil ⇒ Object
Returns the value of attribute oscil.
Instance Method Summary collapse
-
#generate(num_chars, &block) ⇒ Object
Public: Generate text.
-
#initialize(str, options = {}) ⇒ Generator
constructor
str - input String.
Constructor Details
#initialize(str, options = {}) ⇒ Generator
str - input String
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/charosc/generator.rb', line 8 def initialize(str, = {}) @chars = Text.new(str).chars @markov = Markov.new(@chars) = .merge() @depth = [:depth] @mod_enabled = [:mod_enabled] @mod_inc = [:mod_inc] @mod_top = [:mod_top] @mod_bottom = [:mod_bottom] @oscil = Oscillator.new( depth, top: mod_top, bottom: mod_bottom, inc: mod_inc ) end |
Instance Attribute Details
#chars ⇒ Object (readonly)
Returns the value of attribute chars.
3 4 5 |
# File 'lib/charosc/generator.rb', line 3 def chars @chars end |
#depth ⇒ Object
Returns the value of attribute depth.
4 5 6 |
# File 'lib/charosc/generator.rb', line 4 def depth @depth end |
#mod_bottom ⇒ Object
Returns the value of attribute mod_bottom.
4 5 6 |
# File 'lib/charosc/generator.rb', line 4 def mod_bottom @mod_bottom end |
#mod_enabled ⇒ Object
Returns the value of attribute mod_enabled.
4 5 6 |
# File 'lib/charosc/generator.rb', line 4 def mod_enabled @mod_enabled end |
#mod_inc ⇒ Object
Returns the value of attribute mod_inc.
4 5 6 |
# File 'lib/charosc/generator.rb', line 4 def mod_inc @mod_inc end |
#mod_top ⇒ Object
Returns the value of attribute mod_top.
4 5 6 |
# File 'lib/charosc/generator.rb', line 4 def mod_top @mod_top end |
#oscil ⇒ Object
Returns the value of attribute oscil.
4 5 6 |
# File 'lib/charosc/generator.rb', line 4 def oscil @oscil end |
Instance Method Details
#generate(num_chars, &block) ⇒ Object
Public: Generate text
num_chars - Number of characters to generate block - Yields to block after output is concatenated
Returns String
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/charosc/generator.rb', line 33 def generate(num_chars, &block) output = rand_char until output.size > num_chars seq = @markov.get_sequence(output[-1], next_depth) output += seq.join("") yield seq if block_given? end format_text(output[0..(num_chars - 1)]) end |