Sha256: ccba96a6e61c97b238a9863294fd3262a10977a83370e5d7336a418aa8cdeaa7
Contents?: true
Size: 869 Bytes
Versions: 4
Compression:
Stored size: 869 Bytes
Contents
# frozen_string_literal: true require_relative 'dictionary_lookup' module EnumIsh class Dictionary def initialize(klass, enum, options = {}) @klass = klass @enum = enum @options = options @dict = cache { DictionaryLookup.new(@klass, @enum, @options).call } end def translate_value(value) if value.is_a?(Array) value.map { |v| @dict[v] || v } else @dict[value] || value end end def translate_options @dict.to_a.map { |value, text| [text, value] } end private def cache if (cache = EnumIsh::DictionaryCache.cache) != nil cache[I18n.locale] ||= {} cache[I18n.locale][@klass] ||= {} cache[I18n.locale][@klass][@enum] ||= {} cache[I18n.locale][@klass][@enum][@options] ||= yield else yield end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
enum_ish-1.6.3 | lib/enum_ish/dictionary.rb |
enum_ish-1.6.2 | lib/enum_ish/dictionary.rb |
enum_ish-1.6.1 | lib/enum_ish/dictionary.rb |
enum_ish-1.6.0 | lib/enum_ish/dictionary.rb |