class Csv2hash::YamlLoader

Attributes

conf[R]
definition[RW]

Public Class Methods

load!(file) click to toggle source
# File lib/csv2hash/yaml_loader.rb, line 15
def self.load! file
  new(file).tap &:load!
end
new(file) click to toggle source
# File lib/csv2hash/yaml_loader.rb, line 10
def initialize file
  @conf = load_config_file file
  self.conf.deep_symbolize_keys!
end

Public Instance Methods

load!() click to toggle source
# File lib/csv2hash/yaml_loader.rb, line 19
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 Instance Methods

load_config_file(file) click to toggle source
# File lib/csv2hash/yaml_loader.rb, line 39
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