Sha256: 956fda9eb2371394eb78e46fef80b381afece4e49db67e262403f6507eaa9cb6
Contents?: true
Size: 910 Bytes
Versions: 14
Compression:
Stored size: 910 Bytes
Contents
require 'yaml' module Quandl class Lang class << self def en @en ||= self.new( File.join(Quandl::Command.root, 'config/locales/en.yml') ) @en.data end end attr_accessor :data, :file def initialize(file) self.file = file end def data @data ||= convert_to_ostruct_recursive( load_file, {} ) end def load_file YAML.load( File.read( file ) ) end protected def convert_to_ostruct_recursive(obj, options) result = obj if result.is_a? Hash result = result.dup.symbolize_keys! result.each do |key, val| result[key] = convert_to_ostruct_recursive(val, options) unless options[:exclude].try(:include?, key) end result = OpenStruct.new result elsif result.is_a? Array result = result.map { |r| convert_to_ostruct_recursive(r, options) } end return result end end end
Version data entries
14 entries across 14 versions & 1 rubygems