Module: Unitsdb::Database::Reference

Defined in:
lib/unitsdb/database/reference_validator.rb

Overview

Coerces various reference shapes (Identifier instance, Hash with string keys, plain String) into a ReferencePair (or nil if the ref is a bare string with no type metadata).

Class Method Summary collapse

Class Method Details

.destructure(ref) ⇒ Object



183
184
185
186
187
188
189
190
# File 'lib/unitsdb/database/reference_validator.rb', line 183

def destructure(ref)
  case ref
  when Unitsdb::Identifier
    ReferencePair.new(id: ref.id, type: ref.type) if ref.id && ref.type
  when Hash
    ReferencePair.new(id: ref["id"], type: ref["type"]) if ref["id"] && ref["type"]
  end
end