Class: 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
- .register(converter_class) ⇒ Object
Instance Method Summary collapse
- #get_converter_chain(src_type, tgt_type, operations = {}) ⇒ Object
- #get_converters ⇒ Object
-
#initialize ⇒ Repository
constructor
A new instance of Repository.
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 |
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_converters ⇒ Object
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_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.(filename) end end converters end |