Class: Csv2hash::YamlLoader
- Inherits:
-
Object
- Object
- Csv2hash::YamlLoader
- Defined in:
- lib/csv2hash/yaml_loader.rb
Instance Attribute Summary collapse
-
#conf ⇒ Object
readonly
Returns the value of attribute conf.
-
#definition ⇒ Object
Returns the value of attribute definition.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(file) ⇒ YamlLoader
constructor
A new instance of YamlLoader.
- #load! ⇒ Object
Constructor Details
#initialize(file) ⇒ YamlLoader
Returns a new instance of YamlLoader.
10 11 12 13 |
# File 'lib/csv2hash/yaml_loader.rb', line 10 def initialize file @conf = load_config_file file self.conf.deep_symbolize_keys! end |
Instance Attribute Details
#conf ⇒ Object (readonly)
Returns the value of attribute conf.
7 8 9 |
# File 'lib/csv2hash/yaml_loader.rb', line 7 def conf @conf end |
#definition ⇒ Object
Returns the value of attribute definition.
8 9 10 |
# File 'lib/csv2hash/yaml_loader.rb', line 8 def definition @definition end |
Class Method Details
.load!(file) ⇒ Object
15 16 17 |
# File 'lib/csv2hash/yaml_loader.rb', line 15 def self.load! file new(file).tap &:load! end |
Instance Method Details
#load! ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# 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 |