Sha256: 049b7f2413eb7ba440e45b64af265595839ecaea4f812dad0091f7e4443f5bad
Contents?: true
Size: 1.05 KB
Versions: 6
Compression:
Stored size: 1.05 KB
Contents
require 'active_support/core_ext' require 'yaml' module Csv2hash class YamlLoader attr_reader :conf attr_accessor :definition def initialize file @conf = load_config_file file self.conf.deep_symbolize_keys! end def self.load! file new(file).tap &:load! end def load! mapping = self.conf.fetch(:mapping) header_size = self.conf.fetch(:header_size).to_i structure_rules = self.conf.fetch(:structure_rules) self.definition = Main.generate_definition self.conf.fetch(:name) do set_type { mapping } set_header_size { header_size } set_structure_rules { structure_rules } end self.conf.fetch(:rules).each do |rule| definition.cells << Cell.new(rule) end Main[self.conf.fetch(:name)] = self.definition nil end private def load_config_file file if file.to_s =~ /(?<ext>\.erb)/ YAML.load(ERB.new(File.read(file)).result) else YAML.load_file(file) end end end end
Version data entries
6 entries across 6 versions & 1 rubygems