module ProgrammingIpsum::Grammar

Public Instance Methods

agreement_verb() click to toggle source

Returns an agreement verb (for plural nouns) like “renders”

# File lib/programming_ipsum/grammar.rb, line 51
def agreement_verb
  random_verb :agreement
end
Also aliased as: verbs
article(word) click to toggle source

Helper to add an indefinite article to any word Usage:

<%= article singular_noun %>
# File lib/programming_ipsum/grammar.rb, line 15
def article(word)
  @inflector.article(word)
end
gerund_verb() click to toggle source

Returns an gerund verb like “rendering”

# File lib/programming_ipsum/grammar.rb, line 61
def gerund_verb
  random_verb :gerund
end
Also aliased as: verbing
initialize_grammar() click to toggle source
# File lib/programming_ipsum/grammar.rb, line 3
def initialize_grammar
  @inflector = Inflector.new
end
method_missing(key, *args, &block) click to toggle source

Catch-all for allowing other keys than :verb and :noun

# File lib/programming_ipsum/grammar.rb, line 8
def method_missing(key, *args, &block)
  @context.fetch(key, ['INVALID GRAMMAR']).sample
end
noun()
Alias for: singular_noun
nouns()
Alias for: plural_noun
past_verb() click to toggle source

Returns a past tense verb like “rendered”

# File lib/programming_ipsum/grammar.rb, line 56
def past_verb
  random_verb :past
end
Also aliased as: verbed
plural(noun) click to toggle source

Helper to pluralize any word (based on noun rules) Usage:

<%= plural unit_of_measurement %>
# File lib/programming_ipsum/grammar.rb, line 22
def plural(noun)
  @inflector.plural_noun(noun)
end
plural_noun() click to toggle source

Returns a plural noun like “programmers”

# File lib/programming_ipsum/grammar.rb, line 32
def plural_noun
  random_noun :plural
end
Also aliased as: nouns
possessive_noun() click to toggle source

Returns a possessive noun like “programmer's”

# File lib/programming_ipsum/grammar.rb, line 37
def possessive_noun
  random_noun :possessive
end
present_verb() click to toggle source

Returns a present verb, like “render”

# File lib/programming_ipsum/grammar.rb, line 46
def present_verb
  random_verb :present
end
Also aliased as: verb
singular_noun() click to toggle source

Returns a singular noun like “programmer”

# File lib/programming_ipsum/grammar.rb, line 27
def singular_noun
  random_noun :singular
end
Also aliased as: noun
verb()
Alias for: present_verb
verbed()
Alias for: past_verb
verbing()
Alias for: gerund_verb
verbs()
Alias for: agreement_verb

Private Instance Methods

random_noun(type) click to toggle source
# File lib/programming_ipsum/grammar.rb, line 72
def random_noun(type)
  noun = @context[:noun].sample
  noun[type] || @inflector.send("#{type}_noun", noun[:singular])
end
random_verb(type) click to toggle source
# File lib/programming_ipsum/grammar.rb, line 77
def random_verb(type)
  verb = @context[:verb].sample
  verb[type] || @inflector.send("#{type}_verb", verb[:present])
end