Sha256: 81edd2d6be22dda752505d7a657eb48947aa1ebef9411c38a6a11b4555ef88b1
Contents?: true
Size: 1.18 KB
Versions: 1
Compression:
Stored size: 1.18 KB
Contents
# encoding: UTF-8 module TwitterCldr module Shared class Resources def initialize @resources_by_locale = {} end def resource_for(locale, resource) locale = locale.to_sym unless @resources_by_locale.include?(locale) @resources_by_locale[locale] = {} end unless @resources_by_locale[locale].include?(resource) @resources_by_locale[locale][resource] = data_for(locale, resource) end @resources_by_locale[locale][resource] end protected def data_for(locale, resource) deep_symbolize_keys(YAML.load(File.read(TwitterCldr.get_resource_file(locale, resource)))) end # adapted from: http://snippets.dzone.com/posts/show/11121 (first comment) def deep_symbolize_keys(arg) case arg when Array then arg.map { |elem| deep_symbolize_keys(elem) } when Hash then Hash[ arg.map do |key, value| k = key.is_a?(String) ? key.to_sym : key v = deep_symbolize_keys(value) [k, v] end] else arg end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
twitter_cldr-1.0.1 | lib/shared/resources.rb |