Class: Labimotion::MapperUtils
- Inherits:
-
Object
- Object
- Labimotion::MapperUtils
- Defined in:
- lib/labimotion/utils/mapper_utils.rb
Class Method Summary collapse
- .extract_data_from_zip(zip_file_url, source_map) ⇒ Object
- .extract_parameters(file_content, parameter_names) ⇒ Object
- .format_timestamp(timestamp_str, give_format = nil) ⇒ Object
- .load_brucker_config ⇒ Object
- .load_config(config_json) ⇒ Object
Class Method Details
.extract_data_from_zip(zip_file_url, source_map) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/labimotion/utils/mapper_utils.rb', line 37 def extract_data_from_zip(zip_file_url, source_map) return nil if zip_file_url.nil? process_zip_file(zip_file_url, source_map) rescue Zip::Error => e Rails.logger.error "Zip file error: #{e.}" nil rescue StandardError => e Rails.logger.error "Unexpected error extracting metadata: #{e.}" nil end |
.extract_parameters(file_content, parameter_names) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/labimotion/utils/mapper_utils.rb', line 49 def extract_parameters(file_content, parameter_names) return nil if file_content.blank? || parameter_names.blank? patterns = { standard: build_parameter_pattern(parameter_names, :standard), parm: build_parameter_pattern(parameter_names, :parm) } extracted_parameters = {} begin file_content.each_line do |line| if (match = match_parameter(line, patterns)) value = clean_value(match[:value]) extracted_parameters[match[:param_name]] = value end end rescue StandardError => e Rails.logger.error "Error reading file content: #{e.}" return nil end extracted_parameters.compact_blank! extracted_parameters end |
.format_timestamp(timestamp_str, give_format = nil) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/labimotion/utils/mapper_utils.rb', line 73 def (, give_format = nil) return nil if .blank? begin = Integer() time_object = Time.at().in_time_zone(Constants::DateTime::TIME_ZONE) case give_format when 'date' time_object.strftime(Constants::DateTime::DATE_FORMAT) when 'time' time_object.strftime(Constants::DateTime::TIME_FORMAT) else time_object.strftime(Constants::DateTime::DATETIME_FORMAT) end rescue ArgumentError, TypeError => e Rails.logger.error "Error parsing timestamp '#{}': #{e.}" nil end end |
.load_brucker_config ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/labimotion/utils/mapper_utils.rb', line 24 def load_brucker_config config = load_config(File.read(Constants::Mapper::NMR_CONFIG)) return if config.nil? || config['sourceMap'].nil? source_selector = config['sourceMap']['sourceSelector'] return if source_selector.blank? parameters = config['sourceMap']['parameters'] return if parameters.blank? config end |
.load_config(config_json) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/labimotion/utils/mapper_utils.rb', line 11 def load_config(config_json) JSON.parse(config_json) rescue JSON::ParserError => e Rails.logger.error "Error parsing JSON: #{e.}" nil rescue Errno::ENOENT => e Rails.logger.error "Config file not found at #{Constants::Mapper::NMR_CONFIG}: #{e.}" nil rescue StandardError => e Rails.logger.error "Unexpected error loading config: #{e.}" nil end |