module TextEng

Constants

VERSION

Public Class Methods

a() click to toggle source
# File lib/text_eng.rb, line 12
def self.a; ADJECTIVES.sample; end
ad() click to toggle source
# File lib/text_eng.rb, line 13
def self.ad; ADVERBS.sample; end
ar() click to toggle source
# File lib/text_eng.rb, line 14
def self.ar; ARTICLES.sample; end
c() click to toggle source
# File lib/text_eng.rb, line 17
def self.c; CONJUNCTIONS.sample; end
lv() click to toggle source
# File lib/text_eng.rb, line 11
def self.lv; LONG_VERBS.sample; end
n() click to toggle source
# File lib/text_eng.rb, line 8
def self.n; NOUNS.sample; end
paragraph(type = :medium) click to toggle source
# File lib/text_eng.rb, line 45
def self.paragraph(type = :medium)
  if type == :short
    n = rand(2..4)
  elsif type == :long
    n = rand(10..15)
  else
    n = rand(5..9)
  end
  self.sentences(n)
end
paragraphs(n = 3) click to toggle source
# File lib/text_eng.rb, line 56
def self.paragraphs(n = 3)
  block = []
  n.times { block << self.paragraph }
  block.join("\n\n")
end
pcn() click to toggle source
# File lib/text_eng.rb, line 18
def self.pcn; PUNCTUATION.sample; end
pn() click to toggle source
# File lib/text_eng.rb, line 9
def self.pn; PROPER_NOUNS.sample; end
pp() click to toggle source
# File lib/text_eng.rb, line 15
def self.pp; PREPOSITIONS.sample; end
pr() click to toggle source
# File lib/text_eng.rb, line 16
def self.pr; PRONOUNS.sample; end
sentence(type = :medium) click to toggle source
# File lib/text_eng.rb, line 20
def self.sentence(type = :medium)
  #case when
  extend ShortClauses
  return sentencefy(self.short_clauses.first) if type == :short

  extend MediumClauses
  return sentencefy(self.medium_clauses.first) if type == :medium

  extend LongClauses
  return sentencefy(self.long_clauses.sample) if type == :long

  extend PunctuatedClauses

  #for paragraphs and n number of sentences
  if type.is_a?(Fixnum)
    n = type
    paragraph_array = [self.short_clauses,self.medium_clauses,self.punctuated_clauses,self.long_clauses].flatten(1).sample(n)
    return paragraph_array.map {|sentence_array| sentencefy(sentence_array)}.join(" ")
  end
end
sentences(n = 3) click to toggle source
# File lib/text_eng.rb, line 41
def self.sentences(n = 3)
  self.sentence(n)
end
v() click to toggle source
# File lib/text_eng.rb, line 10
def self.v; VERBS.sample; end

Private Class Methods

sentencefy(sentence_array) click to toggle source
# File lib/text_eng.rb, line 64
def self.sentencefy(sentence_array)
  sentencified = sentence_array.join(" ") + '.'
  sentencified[0] = sentencified[0].capitalize
  sentencified
end