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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRepository

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

#convertersObject (readonly)

Returns the value of attribute converters.



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

def converters
  @converters
end

#converters_globObject

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

Class Method Details

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



45
46
47
# File 'lib/libis/format/converter/repository.rb', line 45

def Repository.get_converter_chain(src_type, tgt_type, operations = {})
  instance.get_converter_chain src_type, tgt_type, operations
end

.get_convertersObject



31
32
33
# File 'lib/libis/format/converter/repository.rb', line 31

def Repository.get_converters
  instance.get_converters
end

.register(converter_class) ⇒ Object



27
28
29
# File 'lib/libis/format/converter/repository.rb', line 27

def Repository.register(converter_class)
  instance.converters.add? converter_class
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_convertersObject



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