Module: IsoDoc::I18n::Liquid
- Defined in:
- lib/isodoc/liquid/liquid.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#inflect(word, options) ⇒ Object
word | inflect: nom,sg,neut.
-
#ordinal_num(num, label = "", infl = "") ⇒ Object
num | ordinal_num: label, inflection e.g.
- #ordinal_word(num, label = "", infl = "") ⇒ Object
- #parse_hash(str, symbol: true) ⇒ Object
Class Method Details
.set(i18n) ⇒ Object
4 5 6 |
# File 'lib/isodoc/liquid/liquid.rb', line 4 def self.set(i18n) @@i18n = i18n end |
Instance Method Details
#inflect(word, options) ⇒ Object
word | inflect: nom,sg,neut
16 17 18 |
# File 'lib/isodoc/liquid/liquid.rb', line 16 def inflect(word, ) @@i18n.inflect(word, parse_hash()) end |
#ordinal_num(num, label = "", infl = "") ⇒ Object
num | ordinal_num: label, inflection e.g. “3” | ordinal: “edition”, “case:acc” combines inflection information from label and inflection
23 24 25 26 27 28 |
# File 'lib/isodoc/liquid/liquid.rb', line 23 def ordinal_num(num, label = "", infl = "") l = @@i18n.labels[label] h = @@i18n.labels["inflection"]&.dig(l, "grammar") || {} grammar = h.merge(parse_hash(infl, symbol: false)) @@i18n.inflect_ordinal(num.to_i, grammar, "OrdinalRules") end |
#ordinal_word(num, label = "", infl = "") ⇒ Object
30 31 32 33 34 35 |
# File 'lib/isodoc/liquid/liquid.rb', line 30 def ordinal_word(num, label = "", infl = "") l = @@i18n.labels[label] h = @@i18n.labels["inflection"]&.dig(l, "grammar") || {} grammar = h.merge(parse_hash(infl, symbol: false)) @@i18n.inflect_ordinal(num.to_i, grammar, "SpelloutRules") end |
#parse_hash(str, symbol: true) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/isodoc/liquid/liquid.rb', line 8 def parse_hash(str, symbol: true) str.split(/,\s*/).each_with_object({}) do |e, m| k, v = e.split(/:/, 2) m[symbol ? k.to_sym : k.to_s] = v end end |