You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
678 B
28 lines
678 B
3 years ago
|
module Imports
|
||
|
class ImportService
|
||
|
private
|
||
|
|
||
|
def initialize(storage_service, logger = Rails.logger)
|
||
|
@storage_service = storage_service
|
||
|
@logger = logger
|
||
|
end
|
||
|
|
||
|
def import_from(folder, create_method)
|
||
|
filenames = @storage_service.list_files(folder)
|
||
|
filenames.each do |filename|
|
||
|
file_io = @storage_service.get_file_io(filename)
|
||
|
xml_document = Nokogiri::XML(file_io)
|
||
|
send(create_method, xml_document)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def field_value(xml_document, namespace, field)
|
||
|
xml_document.at_xpath("//#{namespace}:#{field}")&.text
|
||
|
end
|
||
|
|
||
|
def to_boolean(input_string)
|
||
|
input_string == "true"
|
||
|
end
|
||
|
end
|
||
|
end
|