Sha256: c6ef467f92e23a12f04ea123e8c8b39f6cd1c493f535b92ffa4ceaabad099332

Contents?: true

Size: 863 Bytes

Versions: 1

Compression:

Stored size: 863 Bytes

Contents

module Dorsale
  module TextHelper
    def euros(n)
      return if n.nil?

      number(n) + " €"
    end

    def percentage(n)
      return if n.nil?

      number(n) + " %"
    end

    def number(n)
      return if n.nil?

      opts = {}

      if n.class.to_s.match(/Float|Decimal/i)
        opts[:precision] = 2
      else
        opts[:precision] = 0
      end

      opts[:delimiter] = I18n.t("number.format.delimiter")
      opts[:separator] = I18n.t("number.format.separator")

      number_with_precision(n, opts)
    end

    def hours(n)
      return if n.nil?

      number = number_with_precision(n, precision: 2)
      text   = I18n.t("datetime.prompts.hour").downcase
      text   = text.pluralize if n > 1
      "#{number} #{text}"
    end

    def text2html(str)
      h(str).gsub("\r", "").gsub("\n", "<br />").html_safe
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dorsale-1.2.6 app/helpers/dorsale/text_helper.rb