class Libis::Format::Library
Public Class Methods
enrich(info, map_keys = {})
click to toggle source
# File lib/libis/format/library.rb, line 44 def enrich(info, map_keys = {}) instance.enrich(info, map_keys) end
get_field(format, field)
click to toggle source
# File lib/libis/format/library.rb, line 28 def get_field(format, field) instance.get_field(format, field) end
get_field_by(key, value, field)
click to toggle source
# File lib/libis/format/library.rb, line 32 def get_field_by(key, value, field) instance.get_field_by(key, value, field) end
get_fields_by(key, value, field)
click to toggle source
# File lib/libis/format/library.rb, line 36 def get_fields_by(key, value, field) instance.get_fields_by(key, value, field) end
get_info(format)
click to toggle source
# File lib/libis/format/library.rb, line 16 def get_info(format) instance.get_info(format) end
get_info_by(key, value)
click to toggle source
# File lib/libis/format/library.rb, line 20 def get_info_by(key, value) instance.get_info_by(key, value) end
get_infos_by(key, value)
click to toggle source
# File lib/libis/format/library.rb, line 24 def get_infos_by(key, value) instance.get_infos_by(key, value) end
implementation=(impl)
click to toggle source
# File lib/libis/format/library.rb, line 12 def implementation=(impl) instance.implementation = impl end
known?(key, value)
click to toggle source
# File lib/libis/format/library.rb, line 40 def known?(key, value) instance.known?(key, value) end
new()
click to toggle source
# File lib/libis/format/library.rb, line 140 def initialize @implementation = eval(Libis::Format::Config[:format_library_implementation]) end
normalize(info, map_keys = {})
click to toggle source
# File lib/libis/format/library.rb, line 48 def normalize(info, map_keys = {}) instance.normalize(info, map_keys) end
Public Instance Methods
enrich(info, map_keys = {})
click to toggle source
# File lib/libis/format/library.rb, line 97 def enrich(info, map_keys = {}) info = normalize(info, map_keys) mapper = Hash.new { |hash, key| hash[key] = key }.merge(map_keys) unless (format = info[mapper[:name]]).nil? lib_info = get_info(format) mapper.keys.each do |key| case key when :mimetype info[mapper[key]] = lib_info[:mimetypes].first if lib_info[:mimetypes].first when :puid info[mapper[key]] = lib_info[:puids].first if lib_info[:puids].first when :extension info[mapper[key]] = lib_info[:extensions].first if lib_info[:extensions].first else info[mapper[key]] = lib_info[key] if lib_info[key] end end end info end
get_field(format, field)
click to toggle source
# File lib/libis/format/library.rb, line 57 def get_field(format, field) get_field_by(:name, format, field) end
get_field_by(key, value, field)
click to toggle source
# File lib/libis/format/library.rb, line 61 def get_field_by(key, value, field) info = get_info_by(key, value) return nil unless info case field when :mimetype info[:mimetypes]&.first when :puid info[:puids]&.first when :extension info[:extensions]&.first else info[field] end end
get_fields_by(key, value, field)
click to toggle source
# File lib/libis/format/library.rb, line 76 def get_fields_by(key, value, field) get_infos_by(key, value)&.map { |info| info[field] }.compact end
get_info(format)
click to toggle source
# File lib/libis/format/library.rb, line 80 def get_info(format) get_info_by(:name, format) end
get_info_by(key, value)
click to toggle source
# File lib/libis/format/library.rb, line 84 def get_info_by(key, value) get_infos_by(key, value)&.first end
get_infos_by(key, value)
click to toggle source
# File lib/libis/format/library.rb, line 88 def get_infos_by(key, value) result = @implementation.query(key, value) result.map(&:to_hash) end
implementation=(impl)
click to toggle source
# File lib/libis/format/library.rb, line 53 def implementation=(impl) @implementation = impl end
known?(key, value)
click to toggle source
# File lib/libis/format/library.rb, line 93 def known?(key, value) !get_info_by(key, value).nil? end
normalize(info, map_keys = {})
click to toggle source
Derive name from the available info
# File lib/libis/format/library.rb, line 119 def normalize(info, map_keys = {}) return {} unless info.is_a? Hash mapper = Hash.new { |hash, key| hash[key] = key }.merge(map_keys) # fill format from looking up by puid unless (puid = info[mapper[:puid]]).blank? info[mapper[:name]] ||= get_field_by(:puid, puid, :name) end # fill format from looking up by mimetype unless (mime = info[mapper[:mimetype]]).blank? info[mapper[:name]] ||= get_field_by(:mimetype, mime, :name) end # finally complete the information from looking up by format name unless (format = info[mapper[:name]]).nil? info[mapper[:mimetype]] = get_field(format, :mimetype) info[mapper[:category]] = get_field(format, :category) end info end