Sha256: d56b509a409e70576e0d3d1d7d98b639c7501ec6738bd371d94673502e985033
Contents?: true
Size: 1.05 KB
Versions: 1
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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
csv2hash-0.6.6 | lib/csv2hash/yaml_loader.rb |