Sha256: 64e7f32961615660b8761e5bb6d6f30d693c6788e61fcc6634c40a9ed06e31e1
Contents?: true
Size: 830 Bytes
Versions: 18
Compression:
Stored size: 830 Bytes
Contents
module Bisu class Dictionary def initialize(keys) unless keys.is_a?(Hash) raise ArgumentError.new("keys: expected Hash, got #{keys.class}") end keys.each do |lang,v| unless v.is_a?(Hash) raise ArgumentError.new("keys['#{lang}']: expected Hash, got #{v.class}") end v.each do |key,v| unless v.is_a?(String) || v.nil? raise ArgumentError.new("keys['#{lang}']['#{key}']: expected String, got #{v.class}") end end end @keys = Hash[keys.map { |k,v| [k.downcase, v] }] end def has_language?(language) @keys.include?(language&.downcase) end def localize(language, key) if has_language?(language) @keys[language&.downcase][key] else nil end end end end
Version data entries
18 entries across 18 versions & 1 rubygems