Class: Libis::Format::Converter::Repository
- Inherits:
-
Object
- Object
- Libis::Format::Converter::Repository
- Includes:
- Tools::Logger, Singleton
- Defined in:
- lib/libis/format/converter/repository.rb
Instance Attribute Summary collapse
-
#converters ⇒ Object
readonly
Returns the value of attribute converters.
-
#converters_glob ⇒ Object
Returns the value of attribute converters_glob.
Class Method Summary collapse
- .get_converter_chain(src_type, tgt_type, operations = {}) ⇒ Object
-
.get_converters ⇒ Object
rubocop:disable Naming/AccessorMethodName.
- .register(converter_class) ⇒ Object
Instance Method Summary collapse
- #get_converter_chain(src_type, tgt_type, operations = {}) ⇒ Object
-
#get_converters ⇒ Object
rubocop:disable Naming/AccessorMethodName.
-
#initialize ⇒ Repository
constructor
A new instance of Repository.
Constructor Details
#initialize ⇒ Repository
Returns a new instance of Repository.
20 21 22 23 |
# File 'lib/libis/format/converter/repository.rb', line 20 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.
17 18 19 |
# File 'lib/libis/format/converter/repository.rb', line 17 def converters @converters end |
#converters_glob ⇒ Object
Returns the value of attribute converters_glob.
18 19 20 |
# File 'lib/libis/format/converter/repository.rb', line 18 def converters_glob @converters_glob end |
Class Method Details
.get_converter_chain(src_type, tgt_type, operations = {}) ⇒ Object
43 44 45 |
# File 'lib/libis/format/converter/repository.rb', line 43 def self.get_converter_chain(src_type, tgt_type, operations = {}) instance.get_converter_chain src_type, tgt_type, operations end |
.get_converters ⇒ Object
rubocop:disable Naming/AccessorMethodName
29 30 31 |
# File 'lib/libis/format/converter/repository.rb', line 29 def self.get_converters # rubocop:disable Naming/AccessorMethodName instance.get_converters end |
.register(converter_class) ⇒ Object
25 26 27 |
# File 'lib/libis/format/converter/repository.rb', line 25 def self.register(converter_class) instance.converters.add? converter_class end |
Instance Method Details
#get_converter_chain(src_type, tgt_type, operations = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/libis/format/converter/repository.rb', line 47 def get_converter_chain(src_type, tgt_type, operations = {}) msg = "conversion from #{src_type} to #{tgt_type}" 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
rubocop:disable Naming/AccessorMethodName
33 34 35 36 37 38 39 40 41 |
# File 'lib/libis/format/converter/repository.rb', line 33 def get_converters # rubocop:disable Naming/AccessorMethodName if converters.empty? Dir.glob(converters_glob).each do |filename| # noinspection RubyResolve require File.(filename) end end converters end |