Sha256: eb5a5bf25dd0c0d43a7f9fdf0f131143578f0c449d312a1dd4eb6775a73bb6c5
Contents?: true
Size: 1.16 KB
Versions: 1
Compression:
Stored size: 1.16 KB
Contents
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.0 | lib/shared/resources.rb |