Sha256: b0413a5eb844cc0b48694c7a8f41ce58ae430b766fb13d1381dd6b088e620f87

Contents?: true

Size: 1.04 KB

Versions: 64

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/patches/class/common_constructor'
require 'eac_ruby_utils/inflector'

module EacRubyUtils
  module Listable
    class Item
      common_constructor :list, :value, :key, :translation_required, default: [true]

      def to_s
        "I: #{list.item}, V: #{value}, K: #{key}"
      end

      def constant_name
        ::EacRubyUtils::Inflector.variableize("#{list.item}_#{key}").upcase
      end

      def label
        translate('label')
      end

      def description
        translate('description')
      end

      # @return [Array] A two-item array in format `[label, value]`.
      def to_option
        [label, value]
      end

      def translation_required?
        translation_required
      end

      private

      def translate(translate_key)
        full_translate_key = "#{list.i18n_key}.#{key}.#{translate_key}"
        if !::I18n.exists?(full_translate_key) && !translation_required?
          ''
        else
          ::I18n.t(full_translate_key)
        end
      end
    end
  end
end

Version data entries

64 entries across 64 versions & 2 rubygems

Version Path
eac_tools-0.60.2 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.60.1 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.60.0 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.59.0 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.58.0 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.57.0 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.56.1 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.56.0 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.55.7 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.55.6 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.55.5 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.55.4 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.55.3 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.55.2 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_ruby_utils-0.112.0 lib/eac_ruby_utils/listable/item.rb
eac_tools-0.55.1 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_ruby_utils-0.111.0 lib/eac_ruby_utils/listable/item.rb
eac_tools-0.55.0 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.54.0 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.53.0 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb