Class: Concode::Generator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#capitalizeObject (readonly)

Returns the value of attribute capitalize.



5
6
7
# File 'lib/concode/generator.rb', line 5

def capitalize
  @capitalize
end

#charsObject (readonly)

Returns the value of attribute chars.



5
6
7
# File 'lib/concode/generator.rb', line 5

def chars
  @chars
end

#glueObject (readonly)

Returns the value of attribute glue.



5
6
7
# File 'lib/concode/generator.rb', line 5

def glue
  @glue
end

#wordsObject (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_countObject



23
24
25
# File 'lib/concode/generator.rb', line 23

def word_count
  @word_count ||= particles.map(&:size).reduce(:*)
end