Sha256: 1be3090aa2329484cc401b3174e759069c5fe82470892dc16fab3a248e3d3eb5

Contents?: true

Size: 1.53 KB

Versions: 10

Compression:

Stored size: 1.53 KB

Contents

module Exlibris
  module Aleph
    module TabParser
      class Base
        attr_accessor :library, :file_name, :pattern, :pattern_key
        attr_accessor :local_path, :local_file
        attr_accessor :config_array, :config_hash, :hash_key

        def initialize(args)
          @aleph_library = args[:aleph_library]
          @aleph_library.downcase!
          @aleph_file_name = args[:aleph_file_name]
          @aleph_file_name.downcase!
          @pattern = args[:pattern]
          @pattern_key = args[:pattern_key]
          @hash_key = args[:hash_key]
          @aleph_file = "#{args[:aleph_mnt_path]}/#{@aleph_library}/tab/#{@aleph_file_name}"
        end
    
        def to_a
          @config_array ||= parse_file.first
        end
    
        def to_h
          @config_hash ||= parse_file.last
        end
    
        protected
        def parse_file
          config_array = []
          config_hash = {}
          File.open(@aleph_file).each do |line|
             line.chomp!
             config_match = line.match(@pattern)
             if (config_match)
               config_match_hash = {}
               @pattern_key.each do |column, key|
                 config_match_hash[key] = config_match[column].strip
               end
               config_array.push(config_match_hash) unless config_match_hash.empty?
               config_hash[config_match_hash[@hash_key]] = config_match_hash unless config_match_hash.empty?
             end
          end
          return [config_array, config_hash]
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
exlibris-aleph-1.1.0 lib/exlibris/aleph/tabs_parser/base.rb
exlibris-aleph-1.0.8 lib/exlibris/aleph/tabs_parser/base.rb
exlibris-aleph-1.0.7 lib/exlibris/aleph/tabs_parser/base.rb
exlibris-aleph-1.0.6 lib/exlibris/aleph/tabs_parser/base.rb
exlibris-aleph-1.0.5 lib/exlibris/aleph/tabs_parser/base.rb
exlibris-aleph-1.0.4 lib/exlibris/aleph/tabs_parser/base.rb
exlibris-aleph-1.0.3 lib/exlibris/aleph/tabs_parser/base.rb
exlibris-aleph-1.0.2 lib/exlibris/aleph/tabs_parser/base.rb
exlibris-aleph-1.0.1 lib/exlibris/aleph/tabs_parser/base.rb
exlibris-aleph-1.0.0 lib/exlibris/aleph/tabs_parser/base.rb