Sha256: 4bb9d98652e2a144ed9c36bebf009280128059eb590c3d90c54105dd45403997

Contents?: true

Size: 769 Bytes

Versions: 42

Compression:

Stored size: 769 Bytes

Contents

require 'active_support/concern'

module FixnumConcern
  extend ActiveSupport::Concern
  included do
    def to_tiered_times skip_seconds = false
      # Actual calculations
      mm, ss = self.divmod(60)
      hh, mm = mm.divmod(60)
      dd, hh = hh.divmod(24)

      # Presentation
      sentence = []
      sentence << I18n.t("tiered_times.dd", count: dd) unless dd.zero?
      sentence << I18n.t("tiered_times.hh", count: hh) unless hh.zero?
      sentence << I18n.t("tiered_times.mm", count: mm) unless mm.zero?
      sentence << I18n.t("tiered_times.ss", count: ss) if !ss.zero? && !skip_seconds

      # to_sentence è una estensione rails che traduce nella forma più corretta (decisamente migliore del join(", "))
      sentence.to_sentence
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
thecore_backend_commons-3.2.4 config/initializers/concern_integer.rb
thecore_backend_commons-3.2.3 config/initializers/concern_integer.rb
thecore_backend_commons-3.2.2 config/initializers/concern_integer.rb
thecore_backend_commons-3.2.1 config/initializers/concern_integer.rb
thecore_backend_commons-3.2.0 config/initializers/concern_integer.rb
thecore_backend_commons-3.1.9 config/initializers/concern_integer.rb
thecore_backend_commons-3.1.8 config/initializers/concern_integer.rb
thecore_backend_commons-3.1.7 config/initializers/concern_integer.rb
thecore_backend_commons-3.1.6 config/initializers/concern_integer.rb
thecore_backend_commons-3.1.5 config/initializers/concern_integer.rb
thecore_backend_commons-3.1.4 config/initializers/concern_integer.rb
thecore_backend_commons-3.1.3 config/initializers/concern_integer.rb
thecore_backend_commons-3.1.2 config/initializers/concern_integer.rb
thecore_backend_commons-3.1.1 config/initializers/concern_integer.rb
thecore_backend_commons-3.1.0 config/initializers/concern_integer.rb
thecore_backend_commons-3.0.9 config/initializers/concern_integer.rb
thecore_backend_commons-3.0.8 config/initializers/concern_integer.rb
thecore_backend_commons-3.0.7 config/initializers/concern_integer.rb
thecore_backend_commons-3.0.6 lib/patches/integer_extensions.rb
thecore_backend_commons-3.0.5 lib/patches/integer_extensions.rb