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.123.0 lib/eac_ruby_utils/listable/item.rb
eac_ruby_utils-0.121.0 lib/eac_ruby_utils/listable/item.rb
eac_ruby_utils-0.120.0 lib/eac_ruby_utils/listable/item.rb
eac_tools-0.76.1 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.76.0 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.75.2 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_ruby_utils-0.119.2 lib/eac_ruby_utils/listable/item.rb
eac_tools-0.75.1 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.75.0 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_ruby_utils-0.119.1 lib/eac_ruby_utils/listable/item.rb
eac_tools-0.74.1 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.74.0 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.73.0 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_ruby_utils-0.119.0 lib/eac_ruby_utils/listable/item.rb
eac_tools-0.72.0 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_ruby_utils-0.118.1 lib/eac_ruby_utils/listable/item.rb
eac_ruby_utils-0.118.0 lib/eac_ruby_utils/listable/item.rb
eac_tools-0.70.1 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.70.0 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb
eac_tools-0.69.1 sub/eac_ruby_utils/lib/eac_ruby_utils/listable/item.rb