class SadSquid::Sentance

Attributes

adjectives[RW]
adverbs[RW]
nouns[RW]
verbs[RW]

Public Instance Methods

decode(string) click to toggle source
# File lib/sad_squid/sentance.rb, line 46
def decode string
  adjective_factor = 32
  noun_factor = adjective_factor * nouns.length
  verb_factor = noun_factor * verbs.length
  adverb_factor = verb_factor * adverbs.length

  arr = string.split(' ')
  count = arr[0].to_i
  adjective = adjectives.index arr[1]
  noun = nouns.index arr[2]
  verb = verbs.index arr[3]
  adverb = adverbs.index arr[4]

  count + adjective * adjective_factor +
    noun * noun_factor +
    verb * verb_factor +
    adverb * adverb_factor
end
generate() click to toggle source
# File lib/sad_squid/sentance.rb, line 36
def generate
  count = Random.rand(33) + 2
  adjective = adjectives.sample
  noun = nouns.sample
  verb = verbs.sample
  adverb = adverbs.sample

  [count, adjective, noun, verb, adverb].join(" ");
end