Module: Strings::Inflection
- Defined in:
- lib/strings/inflection.rb,
lib/strings/inflection/noun.rb,
lib/strings/inflection/term.rb,
lib/strings/inflection/verb.rb,
lib/strings/inflection/nouns.rb,
lib/strings/inflection/verbs.rb,
lib/strings/inflection/parser.rb,
lib/strings/inflection/version.rb,
lib/strings/inflection/extensions.rb,
lib/strings/inflection/combined_noun.rb,
lib/strings/inflection/configuration.rb
Defined Under Namespace
Modules: Extensions, Nouns, Verbs Classes: CombinedNoun, Configuration, Error, Noun, Parser, Term, Verb
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
-
.configuration ⇒ Object
A configuration object.
-
.configure ⇒ Object
Configure custom inflections.
-
.inflect(word, count, term: :noun) ⇒ Object
Inflect a noun into a correct form.
-
.join_words(*words, **options) ⇒ String
Join a list of words into a single sentence.
-
.Noun(word) ⇒ Object
Create a noun object.
-
.plural?(word, term: :noun) ⇒ Boolean
Check if noun is in plural form.
-
.pluralize(word, term: :noun) ⇒ Object
Inflect a word to its plural form.
-
.reset(scope = :all) ⇒ Object
Reset configuration and remove loaded inflections.
-
.singular?(word, term: :noun) ⇒ Boolean
Check if noun is in singular form.
-
.singularize(word, term: :noun) ⇒ Object
Inflect a pural word to its singular form.
-
.uncountable?(word) ⇒ Boolean
private
Check if word is uncountable.
-
.Verb(word) ⇒ Object
Create a verb object.
Class Method Details
.configuration ⇒ Object
A configuration object
33 34 35 |
# File 'lib/strings/inflection.rb', line 33 def configuration @configuration ||= Configuration.new end |
.configure ⇒ Object
Configure custom inflections
55 56 57 58 59 60 61 |
# File 'lib/strings/inflection.rb', line 55 def configure if block_given? yield configuration else configuration end end |
.inflect(word, count, term: :noun) ⇒ Object
Inflect a noun into a correct form
89 90 91 92 93 |
# File 'lib/strings/inflection.rb', line 89 def inflect(word, count, term: :noun) template = !!(word =~ /\{\{([^\}]+)\}\}/) Parser.parse(template ? word : "{{#{term.upcase[0]}:#{word}}}", count) end |
.join_words(*words, **options) ⇒ String
Join a list of words into a single sentence
197 198 199 |
# File 'lib/strings/inflection.rb', line 197 def join_words(*words, **) CombinedNoun.new(words).join_words(**) end |
.Noun(word) ⇒ Object
Create a noun object
17 18 19 |
# File 'lib/strings/inflection.rb', line 17 def Noun(word) Noun[word] end |
.plural?(word, term: :noun) ⇒ Boolean
Check if noun is in plural form
166 167 168 169 170 171 172 173 174 175 |
# File 'lib/strings/inflection.rb', line 166 def plural?(word, term: :noun) case term.to_sym when :noun, :n Noun[word].plural? when :verb, :v Verb[word].plural? else raise Error, "Unknown option '#{term}' as a term" end end |
.pluralize(word, term: :noun) ⇒ Object
Inflect a word to its plural form
126 127 128 129 130 131 132 133 |
# File 'lib/strings/inflection.rb', line 126 def pluralize(word, term: :noun) case term when :noun, :n Noun[word].plural when :verb, :v Verb[word].plural end end |
.reset(scope = :all) ⇒ Object
Reset configuration and remove loaded inflections
41 42 43 |
# File 'lib/strings/inflection.rb', line 41 def reset(scope = :all) configuration.reset(scope) end |
.singular?(word, term: :noun) ⇒ Boolean
Check if noun is in singular form
145 146 147 148 149 150 151 152 153 154 |
# File 'lib/strings/inflection.rb', line 145 def singular?(word, term: :noun) case term.to_sym when :noun, :n Noun[word].singular? when :verb, :v Verb[word].singular? else raise Error, "Unknown option '#{term}' as a term" end end |
.singularize(word, term: :noun) ⇒ Object
Inflect a pural word to its singular form
106 107 108 109 110 111 112 113 |
# File 'lib/strings/inflection.rb', line 106 def singularize(word, term: :noun) case term when :noun, :n Noun[word].singular when :verb, :v Verb[word].singular end end |
.uncountable?(word) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if word is uncountable
72 73 74 |
# File 'lib/strings/inflection.rb', line 72 def uncountable?(word) Noun[word].uncountable? end |