Module: ProgrammingIpsum::Grammar
- Included in:
- RenderContext
- Defined in:
- lib/programming_ipsum/grammar.rb
Instance Method Summary collapse
-
#agreement_verb ⇒ Object
(also: #verbs)
Returns an agreement verb (for plural nouns) like “renders”.
-
#article(word) ⇒ Object
Helper to add an indefinite article to any word Usage: <%= article singular_noun %>.
-
#gerund_verb ⇒ Object
(also: #verbing)
Returns an gerund verb like “rendering”.
- #initialize_grammar ⇒ Object
-
#method_missing(key, *args, &block) ⇒ Object
Catch-all for allowing other keys than :verb and :noun.
-
#past_verb ⇒ Object
(also: #verbed)
Returns a past tense verb like “rendered”.
-
#plural(noun) ⇒ Object
Helper to pluralize any word (based on noun rules) Usage: <%= plural unit_of_measurement %>.
-
#plural_noun ⇒ Object
(also: #nouns)
Returns a plural noun like “programmers”.
-
#possessive_noun ⇒ Object
Returns a possessive noun like “programmer’s”.
-
#present_verb ⇒ Object
(also: #verb)
Returns a present verb, like “render”.
-
#singular_noun ⇒ Object
(also: #noun)
Returns a singular noun like “programmer”.
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_verb ⇒ Object 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_verb ⇒ Object 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_grammar ⇒ Object
3 4 5 |
# File 'lib/programming_ipsum/grammar.rb', line 3 def initialize_grammar @inflector = Inflector.new end |
#past_verb ⇒ Object 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_noun ⇒ Object 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_noun ⇒ Object
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_verb ⇒ Object 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_noun ⇒ Object 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 |