Module: IceCube::StringBuilder::Helpers
- Included in:
- IceCube::StringBuilder
- Defined in:
- lib/ice_cube/builders/string_builder.rb
Instance Method Summary collapse
- #literal_ordinal(number) ⇒ Object
- #nice_number(number) ⇒ Object
- #ordinal(number) ⇒ Object
- #ordinalize(number) ⇒ Object
-
#sentence(array) ⇒ Object
influenced by ActiveSupport’s to_sentence.
Instance Method Details
#literal_ordinal(number) ⇒ Object
56 57 58 |
# File 'lib/ice_cube/builders/string_builder.rb', line 56 def literal_ordinal(number) IceCube::I18n.t("ice_cube.integer.literal_ordinals")[number] end |
#nice_number(number) ⇒ Object
48 49 50 |
# File 'lib/ice_cube/builders/string_builder.rb', line 48 def nice_number(number) literal_ordinal(number) || ordinalize(number) end |
#ordinal(number) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/ice_cube/builders/string_builder.rb', line 60 def ordinal(number) ord = IceCube::I18n.t("ice_cube.integer.ordinals")[number] || IceCube::I18n.t("ice_cube.integer.ordinals")[number % 10] || IceCube::I18n.t("ice_cube.integer.ordinals")[:default] (number >= 0) ? ord : IceCube::I18n.t("ice_cube.integer.negative", ordinal: ord) end |
#ordinalize(number) ⇒ Object
52 53 54 |
# File 'lib/ice_cube/builders/string_builder.rb', line 52 def ordinalize(number) IceCube::I18n.t("ice_cube.integer.ordinal", number: number, ordinal: ordinal(number)) end |
#sentence(array) ⇒ Object
influenced by ActiveSupport’s to_sentence
39 40 41 42 43 44 45 46 |
# File 'lib/ice_cube/builders/string_builder.rb', line 39 def sentence(array) case array.length when 0 then "" when 1 then array[0].to_s when 2 then "#{array[0]}#{IceCube::I18n.t("ice_cube.array.two_words_connector")}#{array[1]}" else; "#{array[0...-1].join(IceCube::I18n.t("ice_cube.array.words_connector"))}#{IceCube::I18n.t("ice_cube.array.last_word_connector")}#{array[-1]}" end end |