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_ruby_utils-0.117.1 lib/eac_ruby_utils/listable/item.rb
eac_tools-0.69.0 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.68.0 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.67.1 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_ruby_utils-0.117.0 lib/eac_ruby_utils/listable/item.rb
eac_tools-0.67.0 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.66.0 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.65.1 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_ruby_utils-0.116.0 lib/eac_ruby_utils/listable/item.rb
eac_ruby_utils-0.115.0 lib/eac_ruby_utils/listable/item.rb
eac_tools-0.65.0 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_ruby_utils-0.114.0 lib/eac_ruby_utils/listable/item.rb
eac_tools-0.64.0 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_ruby_utils-0.113.0 lib/eac_ruby_utils/listable/item.rb
eac_tools-0.63.0 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.62.1 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.62.0 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.61.1 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.61.0 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.60.3 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb