Class: Libis::Format::Converter::Repository

Inherits:
Object
  • Object
show all
Includes:
Tools::Logger, Singleton
Defined in:
lib/libis/format/converter/repository.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Repository

Returns a new instance of Repository.



22
23
24
25
# File 'lib/libis/format/converter/repository.rb', line 22

def initialize
  @converters = Set.new
  @converters_glob = File.join(File.dirname(__FILE__), '*_converter.rb')
end

Instance Attribute Details

#converters ⇒ Object (readonly)

Returns the value of attribute converters.



19
20
21
# File 'lib/libis/format/converter/repository.rb', line 19

def converters
  @converters
end

#converters_glob ⇒ Object

Returns the value of attribute converters_glob.



20
21
22
# File 'lib/libis/format/converter/repository.rb', line 20

def converters_glob
  @converters_glob
end

Instance Method Details

#get_converter_chain(src_type, tgt_type, operations = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/libis/format/converter/repository.rb', line 49

def get_converter_chain(src_type, tgt_type, operations = {})
  msg = "conversion from #{src_type.to_s} to #{tgt_type.to_s}"
  chain_list = find_chains src_type, tgt_type, operations
  # if chain_list.length > 1
  #   warn "Found more than one conversion chain for #{msg}. Picking the first one."
  # end
  if chain_list.empty?
    error "No conversion chain found for #{msg}"
    return nil
  end
  # chain_list.each do |chain|
  #   debug "Matched chain: #{chain}"
  # end
  chain_list[0]
end

#get_converters ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/libis/format/converter/repository.rb', line 35

def get_converters
  if converters.empty?
    Dir.glob(converters_glob).each do |filename|
      # noinspection RubyResolve
      require File.expand_path(filename)
    end
  end
  converters
end