Class: SleepingKingStudios::Tools::Toolbox::Inflector::Rules
- Inherits:
-
Object
- Object
- SleepingKingStudios::Tools::Toolbox::Inflector::Rules
- Defined in:
- lib/sleeping_king_studios/tools/toolbox/inflector/rules.rb
Overview
Rules for inflecting words.
Instance Attribute Summary collapse
-
#irregular_words ⇒ Array<Array<(String, String)>] Hash of irregular word pairs in singular => plural order.
readonly
Array<Array<(String, String)>] Hash of irregular word pairs in singular => plural order.
-
#irregular_words_reversed ⇒ Array<Array<(String, String)>] Hash of irregular word pairs in plural => singular order.
readonly
Array<Array<(String, String)>] Hash of irregular word pairs in plural => singular order.
-
#plural_rules ⇒ Array<Array<(Regexp, String)>>
readonly
Rules for pluralizing words.
-
#singular_rules ⇒ Array<Array<(Regexp, String)>>
readonly
Rules for singularizing words.
-
#uncountable_words ⇒ Array<String>
readonly
List of uncountable words.
Instance Method Summary collapse
-
#define_irregular_word(singular, plural) ⇒ Rules
Defines an irregular word pair.
-
#define_plural_rule(pattern, replace) ⇒ Rules
Defines a pluralization rule.
-
#define_singular_rule(pattern, replace) ⇒ Rules
Defines a singularization rule.
-
#define_uncountable_word(word) ⇒ Rules
Defines an uncountable word.
-
#initialize(irregular_words: nil, plural_rules: nil, singular_rules: nil, uncountable_words: nil) ⇒ Rules
constructor
A new instance of Rules.
-
#inspect ⇒ String
A human-readable representation of the rules object.
Constructor Details
#initialize(irregular_words: nil, plural_rules: nil, singular_rules: nil, uncountable_words: nil) ⇒ Rules
Returns a new instance of Rules.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/sleeping_king_studios/tools/toolbox/inflector/rules.rb', line 18 def initialize( irregular_words: nil, plural_rules: nil, singular_rules: nil, uncountable_words: nil ) @plural_rules = plural_rules || default_plural_rules @singular_rules = singular_rules || default_singular_rules @irregular_words = irregular_words || default_irregular_words @uncountable_words = Set.new(uncountable_words || default_uncountable_words) @irregular_words_reversed = reverse_hash(@irregular_words) end |
Instance Attribute Details
#irregular_words ⇒ Array<Array<(String, String)>] Hash of irregular word pairs in singular => plural order. (readonly)
Returns Array<Array<(String, String)>] Hash of irregular word pairs in singular => plural order.
35 36 37 |
# File 'lib/sleeping_king_studios/tools/toolbox/inflector/rules.rb', line 35 def irregular_words @irregular_words end |
#irregular_words_reversed ⇒ Array<Array<(String, String)>] Hash of irregular word pairs in plural => singular order. (readonly)
Returns Array<Array<(String, String)>] Hash of irregular word pairs in plural => singular order.
39 40 41 |
# File 'lib/sleeping_king_studios/tools/toolbox/inflector/rules.rb', line 39 def irregular_words_reversed @irregular_words_reversed end |
#plural_rules ⇒ Array<Array<(Regexp, String)>> (readonly)
Returns Rules for pluralizing words.
42 43 44 |
# File 'lib/sleeping_king_studios/tools/toolbox/inflector/rules.rb', line 42 def plural_rules @plural_rules end |
#singular_rules ⇒ Array<Array<(Regexp, String)>> (readonly)
Returns Rules for singularizing words.
45 46 47 |
# File 'lib/sleeping_king_studios/tools/toolbox/inflector/rules.rb', line 45 def singular_rules @singular_rules end |
#uncountable_words ⇒ Array<String> (readonly)
Returns List of uncountable words.
48 49 50 |
# File 'lib/sleeping_king_studios/tools/toolbox/inflector/rules.rb', line 48 def uncountable_words @uncountable_words end |
Instance Method Details
#define_irregular_word(singular, plural) ⇒ Rules
Defines an irregular word pair.
56 57 58 59 60 61 62 63 64 |
# File 'lib/sleeping_king_studios/tools/toolbox/inflector/rules.rb', line 56 def define_irregular_word(singular, plural) validate_string(singular) validate_string(plural) @irregular_words[singular] = plural @irregular_words_reversed[plural] = singular self end |
#define_plural_rule(pattern, replace) ⇒ Rules
Defines a pluralization rule.
72 73 74 75 76 77 78 79 |
# File 'lib/sleeping_king_studios/tools/toolbox/inflector/rules.rb', line 72 def define_plural_rule(pattern, replace) validate_pattern(pattern) validate_string(replace, as: 'replace') @plural_rules.unshift([pattern, replace]) self end |
#define_singular_rule(pattern, replace) ⇒ Rules
Defines a singularization rule.
87 88 89 90 91 92 93 94 |
# File 'lib/sleeping_king_studios/tools/toolbox/inflector/rules.rb', line 87 def define_singular_rule(pattern, replace) validate_pattern(pattern) validate_string(replace, as: 'replace') @singular_rules.unshift([pattern, replace]) self end |
#define_uncountable_word(word) ⇒ Rules
Defines an uncountable word.
101 102 103 104 105 106 107 |
# File 'lib/sleeping_king_studios/tools/toolbox/inflector/rules.rb', line 101 def define_uncountable_word(word) validate_string(word) @uncountable_words << word self end |
#inspect ⇒ String
Returns A human-readable representation of the rules object.
110 111 112 |
# File 'lib/sleeping_king_studios/tools/toolbox/inflector/rules.rb', line 110 def inspect "#<SleepingKingStudios::Tools::Toolbox::Inflector::Rules:#{object_id}>" end |