Sha256: 88206a85b4c67d4c9737490620181d574c5a91abca59f569e95c3a40d7cc1ab1
Contents?: true
Size: 1.1 KB
Versions: 2
Compression:
Stored size: 1.1 KB
Contents
module LanguageCards class YAMLLoader def initialize @language = CARD_LANGUAGE end def load cards = {} cards_yaml.each do |c| next unless yaml_data = YAML.load(File.open(c).read) for language in yaml_data.keys do # Merges sub-items for languages if cards.has_key? language cards[language] = Hash( cards[language] ).merge( Hash(yaml_data[language]) ) else # Merges in new top scope languages cards.merge!({ language => yaml_data[language] }) end end end cards end private attr_reader :language def application_path File.expand_path(File.join('..','..'), __dir__) end def cards_yaml application_path_cards_yaml + home_path_cards_yaml end def application_path_cards_yaml Dir[File.join(application_path, 'cards', language, '*.yml')] end def home_path_cards_yaml if ENV['HOME'] Dir[File.join(ENV['HOME'], '.language_cards', 'cards', language, '*.yml')] else [] end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
language_cards-0.3.2 | lib/language_cards/yaml_loader.rb |
language_cards-0.3.1 | lib/language_cards/yaml_loader.rb |