Class: Unitsdb::Commands::Ucum::Update

Inherits:
Base
  • Object
show all
Defined in:
lib/unitsdb/commands/ucum/update.rb

Overview

Command to update UnitsDB with UCUM references

Constant Summary collapse

ENTITY_TYPES =

Constants

%w[units prefixes].freeze

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Unitsdb::Commands::Base

Instance Method Details

#runObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/unitsdb/commands/ucum/update.rb', line 18

def run
  # Get options
  entity_type = @options[:entity_type]&.downcase
  database_path = @options[:database]
  ucum_file = @options[:ucum_file]
  output_dir = @options[:output_dir] || database_path
  include_potential = @options[:include_potential_matches] || false

  # Validate database path
  unless File.exist?(database_path) && Dir.exist?(database_path)
    puts "Database directory path: #{database_path}"
    puts "ERROR: Database directory not found: #{database_path}"
    return 1
  end
  puts "Using database directory: #{database_path}"

  # Validate UCUM file
  unless File.exist?(ucum_file)
    puts "ERROR: UCUM file not found: #{ucum_file}"
    return 1
  end
  puts "Using UCUM file: #{ucum_file}"
  puts "Include potential matches: #{include_potential ? "Yes" : "No"}"

  # Parse UCUM XML file
  ucum_data = XmlParser.parse_ucum_file(ucum_file)

  # Process entity types
  if entity_type && ENTITY_TYPES.include?(entity_type)
    process_entity_type(entity_type, ucum_data, output_dir, include_potential)
  else
    ENTITY_TYPES.each do |type|
      process_entity_type(type, ucum_data, output_dir, include_potential)
    end
  end

  0
end