Module: ProgrammingIpsum::Grammar

Included in:
RenderContext
Defined in:
lib/programming_ipsum/grammar.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(key, *args, &block) ⇒ Object

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



8
9
10
# File 'lib/programming_ipsum/grammar.rb', line 8

def method_missing(key, *args, &block)
  @context.fetch(key, ['INVALID GRAMMAR']).sample
end

Instance Method Details

#agreement_verbObject Also known as: verbs

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



51
52
53
# File 'lib/programming_ipsum/grammar.rb', line 51

def agreement_verb
  random_verb :agreement
end

#article(word) ⇒ Object

Helper to add an indefinite article to any word Usage:

<%= article singular_noun %>


15
16
17
# File 'lib/programming_ipsum/grammar.rb', line 15

def article(word)
  @inflector.article(word)
end

#gerund_verbObject Also known as: verbing

Returns an gerund verb like “rendering”



61
62
63
# File 'lib/programming_ipsum/grammar.rb', line 61

def gerund_verb
  random_verb :gerund
end

#initialize_grammarObject



3
4
5
# File 'lib/programming_ipsum/grammar.rb', line 3

def initialize_grammar
  @inflector = Inflector.new
end

#past_verbObject Also known as: verbed

Returns a past tense verb like “rendered”



56
57
58
# File 'lib/programming_ipsum/grammar.rb', line 56

def past_verb
  random_verb :past
end

#plural(noun) ⇒ Object

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

<%= plural unit_of_measurement %>


22
23
24
# File 'lib/programming_ipsum/grammar.rb', line 22

def plural(noun)
  @inflector.plural_noun(noun)
end

#plural_nounObject Also known as: nouns

Returns a plural noun like “programmers”



32
33
34
# File 'lib/programming_ipsum/grammar.rb', line 32

def plural_noun
  random_noun :plural
end

#possessive_nounObject

Returns a possessive noun like “programmer’s”



37
38
39
# File 'lib/programming_ipsum/grammar.rb', line 37

def possessive_noun
  random_noun :possessive
end

#present_verbObject Also known as: verb

Returns a present verb, like “render”



46
47
48
# File 'lib/programming_ipsum/grammar.rb', line 46

def present_verb
  random_verb :present
end

#singular_nounObject Also known as: noun

Returns a singular noun like “programmer”



27
28
29
# File 'lib/programming_ipsum/grammar.rb', line 27

def singular_noun
  random_noun :singular
end