Module: SBuilder

Defined in:
lib/s_builder.rb,
lib/s_builder/version.rb

Defined Under Namespace

Classes: Sentence

Constant Summary collapse

Matches =
{
  verb: "$verb",
  adjective: "$adjective",
  noun: "$noun"
}
VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.fill_sentence(sentence, words) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/s_builder.rb', line 13

def fill_sentence sentence,words
  sentence.words.map do |word|
    case word
    when Matches[:verb]
      words[:verbs][rand(0...words[:verbs].length)]
    when Matches[:adjective]
      words[:adjectives][rand(0...words[:adjectives].length)]
    when Matches[:noun]
      words[:nouns][rand(0...words[:nouns].length)]
    else
      word
    end
  end.join(' ')
end

.generate_sentence(input) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/s_builder.rb', line 28

def generate_sentence input
  sentence = Sentence.new

  sentence.sentence = input
  sentence.words = sentence.sentence.split(Regexp.new(" |\n")) - ['']
  sentence.verbs = []
  sentence.adjectives = []
  sentence.nouns = []
  Matches.each_with_object(sentence.words) do |(match,matcher),words|
    words.each_with_index do |word,index|
      sentence.send("#{match}s") << index if matcher == word
    end
  end
  sentence
end