Class: Concode::Generator
- Inherits:
-
Object
- Object
- Concode::Generator
- Defined in:
- lib/concode/generator.rb
Instance Attribute Summary collapse
-
#capitalize ⇒ Object
readonly
Returns the value of attribute capitalize.
-
#chars ⇒ Object
readonly
Returns the value of attribute chars.
-
#glue ⇒ Object
readonly
Returns the value of attribute glue.
-
#words ⇒ Object
readonly
Returns the value of attribute words.
Instance Method Summary collapse
- #generate(text) ⇒ Object
-
#initialize(words: 2, chars: 0, glue: '-', capitalize: false) ⇒ Generator
constructor
A new instance of Generator.
- #word_count ⇒ Object
Constructor Details
#initialize(words: 2, chars: 0, glue: '-', capitalize: false) ⇒ Generator
Returns a new instance of Generator.
7 8 9 10 11 12 13 14 15 |
# File 'lib/concode/generator.rb', line 7 def initialize(words: 2, chars: 0, glue: '-', capitalize: false) @words = words @glue = glue @capitalize = capitalize @chars = chars @chars = 3 if @chars.between? 1, 3 @chars = 0 if @chars > 9 end |
Instance Attribute Details
#capitalize ⇒ Object (readonly)
Returns the value of attribute capitalize.
5 6 7 |
# File 'lib/concode/generator.rb', line 5 def capitalize @capitalize end |
#chars ⇒ Object (readonly)
Returns the value of attribute chars.
5 6 7 |
# File 'lib/concode/generator.rb', line 5 def chars @chars end |
#glue ⇒ Object (readonly)
Returns the value of attribute glue.
5 6 7 |
# File 'lib/concode/generator.rb', line 5 def glue @glue end |
#words ⇒ Object (readonly)
Returns the value of attribute words.
5 6 7 |
# File 'lib/concode/generator.rb', line 5 def words @words end |
Instance Method Details
#generate(text) ⇒ Object
17 18 19 20 21 |
# File 'lib/concode/generator.rb', line 17 def generate(text) result = generate_particles text result.map!(&:capitalize) if capitalize result.join glue end |
#word_count ⇒ Object
23 24 25 |
# File 'lib/concode/generator.rb', line 23 def word_count @word_count ||= particles.map(&:size).reduce(:*) end |