Sha256: ffbc2e77d95728004d4e7737be19d85ce5530a5eed27695e5e9f2bf849791c15

Contents?: true

Size: 883 Bytes

Versions: 4

Compression:

Stored size: 883 Bytes

Contents

require 'csv'

module BerkeleyLibrary
  module TIND
    module Mapping
      module CsvMultipleMapper
        @rows = []
        class << self
          attr_accessor :rows
        end

        CsvMultipleMapper.rows = Util.csv_rows(Config.one_to_multiple_map_file)
        def from_tags
          tags = []
          CsvMultipleMapper.rows.each do |row|
            tag = row[:tag_origin]
            tags << tag unless tags.include?(tag)
          end
          tags
        end

        def rules
          from_tags.to_h { |tag| [Util.tag_symbol(tag), rules_on_tag(tag)] }
        end

        private

        def rules_on_tag(tag)
          rules = []
          CsvMultipleMapper.rows.each do |row|
            origin_tag = row[:tag_origin]
            rules << MultipleRule.new(row) if origin_tag == tag
          end

          rules
        end

      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
berkeley_library-tind-0.7.2 lib/berkeley_library/tind/mapping/csv_multiple_mapper.rb
berkeley_library-tind-0.7.1 lib/berkeley_library/tind/mapping/csv_multiple_mapper.rb
berkeley_library-tind-0.7.0 lib/berkeley_library/tind/mapping/csv_multiple_mapper.rb
berkeley_library-tind-0.6.0 lib/berkeley_library/tind/mapping/csv_multiple_mapper.rb