Sha256: 6b489ac087a81ef4fd0fa6882077b3a42e38285a33bf281a9c0aed48f84c51bb

Contents?: true

Size: 978 Bytes

Versions: 4

Compression:

Stored size: 978 Bytes

Contents

require "yaml"
require 'forwardable'
require "cascade/exceptions"
require "cascade/helpers/configuration"

module Cascade
  class ColumnsMatching
    extend Forwardable
    extend Configuration

    define_setting :mapping_file

    def_delegator :supported_keys, :index

    def initialize(options = {})
      @filepath = options[:filepath]
      @content = options.fetch(:content) { parse_content_file }
    end

    # Defines set of possible keys that can be used for iterating through
    # parsed line
    #
    # @return [Array] of supported keys
    def supported_keys
      @supported_keys ||= @content.keys
    end

    # Presenter for passed key
    #
    # @return [Symbol] with curresponding value
    def column_type(key)
      @content[key].to_sym
    end

    private

    def parse_content_file
      content = YAML.load_file(@filepath || self.class.mapping_file)
      (content && content["mapping"]) || raise(Cascade::WrongMappingFormat.new)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cascade-rb-0.2.3 lib/cascade/columns_matching.rb
cascade-rb-0.2.2 lib/cascade/columns_matching.rb
cascade-rb-0.2.1 lib/cascade/columns_matching.rb
cascade-rb-0.2.0 lib/cascade/columns_matching.rb