Module: Unitsdb::Commands::Ucum::XmlParser

Defined in:
lib/unitsdb/commands/ucum/xml_parser.rb

Overview

Parser for UCUM XML files

Class Method Summary collapse

Class Method Details

.get_entities_from_ucum(entity_type, ucum_data) ⇒ Object

Get entities from parsed UCUM data based on entity type



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/unitsdb/commands/ucum/xml_parser.rb', line 20

def get_entities_from_ucum(entity_type, ucum_data)
  case entity_type
  when "prefixes"
    ucum_data.prefixes
  when "units"
    # Combine base-units and units into a single array
    ucum_data.base_units + ucum_data.units
  else
    []
  end
end

.parse_ucum_file(file_path) ⇒ Object

Parse UCUM XML file and return parsed data



13
14
15
16
17
# File 'lib/unitsdb/commands/ucum/xml_parser.rb', line 13

def parse_ucum_file(file_path)
  puts "Parsing UCUM XML file: #{file_path}..."
  content = File.read(file_path)
  Unitsdb::UcumFile.from_xml(content)
end