Module: Unitsdb::Commands::Ucum::Formatter
- Defined in:
- lib/unitsdb/commands/ucum/formatter.rb
Overview
Formats output for UCUM matching results
Class Method Summary collapse
-
.display_db_results(entity_type, matches, missing_refs, unmatched_db) ⇒ Object
Display results for UnitsDB → UCUM matching.
-
.display_ucum_results(entity_type, matches, missing_matches, unmatched_ucum) ⇒ Object
Display results for UCUM → UnitsDB matching.
-
.get_db_entity_id(entity) ⇒ Object
Helper to get db entity id.
-
.get_db_entity_name(entity) ⇒ Object
Helper to get db entity name.
-
.get_ucum_entity_name(entity) ⇒ Object
Helper to get ucum entity name.
-
.print_direction_header(direction) ⇒ Object
Print a direction header (UnitsDB → UCUM or UCUM → UnitsDB).
Class Method Details
.display_db_results(entity_type, matches, missing_refs, unmatched_db) ⇒ Object
Display results for UnitsDB → UCUM matching
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/unitsdb/commands/ucum/formatter.rb', line 65 def display_db_results(entity_type, matches, missing_refs, unmatched_db) puts "\nResults for #{entity_type.capitalize} (UnitsDB → UCUM):" puts " Matched: #{matches.size}" puts " Missing references (could be added): #{missing_refs.size}" puts " Unmatched UnitsDB entities: #{unmatched_db.size}" unless unmatched_db.empty? puts "\nUnmatched UnitsDB #{entity_type}:" unmatched_db.each do |entity| id = get_db_entity_id(entity) name = get_db_entity_name(entity) puts " - #{name} (#{id})" end end return if missing_refs.empty? puts "\nPotential references (UCUM references that could be added to UnitsDB):" missing_refs.each do |match| ucum_entity = match[:ucum_entity] db_entity = match[:db_entity] # Get entity IDs and names db_id = get_db_entity_id(db_entity) db_name = get_db_entity_name(db_entity) ucum_name = get_ucum_entity_name(ucum_entity) ucum_code = ucum_entity.code_sensitive || "unknown" case ucum_entity when Unitsdb::UcumPrefix puts " - UnitsDB prefix '#{db_name}' (#{db_id}) → UCUM prefix '#{ucum_name}' (#{ucum_code})" when Unitsdb::UcumBaseUnit puts " - UnitsDB unit '#{db_name}' (#{db_id}) → UCUM base unit '#{ucum_name}' (#{ucum_code})" when Unitsdb::UcumUnit puts " - UnitsDB unit '#{db_name}' (#{db_id}) → UCUM unit '#{ucum_name}' (#{ucum_code})" end end end |
.display_ucum_results(entity_type, matches, missing_matches, unmatched_ucum) ⇒ Object
Display results for UCUM → UnitsDB matching
16 17 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 56 57 58 59 60 61 62 |
# File 'lib/unitsdb/commands/ucum/formatter.rb', line 16 def display_ucum_results(entity_type, matches, missing_matches, unmatched_ucum) puts "\nResults for #{entity_type.capitalize} (UCUM → UnitsDB):" puts " Matched: #{matches.size}" puts " Missing matches (could be added): #{missing_matches.size}" puts " Unmatched UCUM entities: #{unmatched_ucum.size}" unless unmatched_ucum.empty? puts "\nUnmatched UCUM #{entity_type}:" unmatched_ucum.each do |entity| case entity when Unitsdb::UcumPrefix puts " - #{entity.name} (#{entity.code_sensitive})" when Unitsdb::UcumBaseUnit puts " - #{entity.name} (#{entity.code_sensitive}, dimension: #{entity.dimension})" when Unitsdb::UcumUnit name = entity.name.is_a?(Array) ? entity.name.first : entity.name puts " - #{name} (#{entity.code_sensitive}, class: #{entity.klass})" else puts " - Unknown entity type" end end end return if missing_matches.empty? puts "\nPotential additions (UCUM #{entity_type} that could be added to UnitsDB):" missing_matches.each do |match| ucum_entity = match[:ucum_entity] db_entity = match[:db_entity] # Get entity IDs and names db_id = get_db_entity_id(db_entity) db_name = get_db_entity_name(db_entity) ucum_name = get_ucum_entity_name(ucum_entity) ucum_code = ucum_entity.code_sensitive || "unknown" case ucum_entity when Unitsdb::UcumPrefix puts " - UnitsDB prefix '#{db_name}' (#{db_id}) → UCUM prefix '#{ucum_name}' (#{ucum_code})" when Unitsdb::UcumBaseUnit puts " - UnitsDB unit '#{db_name}' (#{db_id}) → UCUM base unit '#{ucum_name}' (#{ucum_code})" when Unitsdb::UcumUnit puts " - UnitsDB unit '#{db_name}' (#{db_id}) → UCUM unit '#{ucum_name}' (#{ucum_code})" end end end |
.get_db_entity_id(entity) ⇒ Object
Helper to get db entity id
105 106 107 108 109 |
# File 'lib/unitsdb/commands/ucum/formatter.rb', line 105 def get_db_entity_id(entity) return entity.identifiers.first.id unless entity.identifiers.empty? entity.short || "unknown-id" end |
.get_db_entity_name(entity) ⇒ Object
Helper to get db entity name
112 113 114 115 116 117 |
# File 'lib/unitsdb/commands/ucum/formatter.rb', line 112 def get_db_entity_name(entity) return entity.names.first.value unless entity.names.empty? return entity.short if entity.short "unknown-name" end |
.get_ucum_entity_name(entity) ⇒ Object
Helper to get ucum entity name
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/unitsdb/commands/ucum/formatter.rb', line 120 def get_ucum_entity_name(entity) case entity when Unitsdb::UcumPrefix, Unitsdb::UcumBaseUnit entity.name when Unitsdb::UcumUnit entity.name.is_a?(Array) ? entity.name.first : entity.name else "unknown-name" end end |
.print_direction_header(direction) ⇒ Object
Print a direction header (UnitsDB → UCUM or UCUM → UnitsDB)
11 12 13 |
# File 'lib/unitsdb/commands/ucum/formatter.rb', line 11 def print_direction_header(direction) puts "\n=== #{direction} ===\n" end |