Class: RDF::Tabular::Schema
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/rdf-tabular-52804f52e930/lib/rdf/tabular/metadata.rb
Constant Summary collapse
- PROPERTIES =
{ :@id => :link, :@type => :atomic, columns: :array, foreignKeys: :array, primaryKey: :column_reference, rowTitles: :column_reference, }.freeze
- DEFAULTS =
{}.freeze
- REQUIRED =
[].freeze
Constants inherited from Metadata
Metadata::DATATYPES, Metadata::INHERITED_DEFAULTS, Metadata::INHERITED_PROPERTIES, Metadata::LOCAL_CONTEXT, Metadata::NAME_SYNTAX
Constants included from Util::Logger
Instance Attribute Summary
Attributes inherited from Metadata
#filenames, #id, #object, #parent, #url
Instance Method Summary collapse
- #columns=(value) ⇒ Object
-
#foreign_keys_referencing(table) ⇒ Array<Hash>
List of foreign keys referencing the specified table.
- #foreignKeys=(value) ⇒ Object
-
#to_atd ⇒ Object
Return Annotated Table representation.
Methods inherited from Metadata
#==, #[], #[]=, #base, #common_properties, #context, #datatype=, #default_value, #describes_file?, #dialect, #dialect=, #each, #each_row, for_input, #has_annotations?, #initialize, #inspect, #normalize!, #normalize_jsonld, open, #root, #set_array_value, #set_nl, #set_property, site_wide_config, #tableSchema=, #tables=, #to_json, #transformations=, #type, #valid?, #valid_natural_language_property?, #validate, #validate!, #verify_compatible!
Methods included from Util::Logger
#log_debug, #log_depth, #log_error, #log_fatal, #log_info, #log_recover, #log_recovering?, #log_statistics, #log_warn, #logger
Constructor Details
This class inherits a constructor from RDF::Tabular::Metadata
Instance Method Details
#columns=(value) ⇒ Object
1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-tabular-52804f52e930/lib/rdf/tabular/metadata.rb', line 1492 def columns=(value) object[:columns] = case value when Array number = 0 value.map do |v| number += 1 case v when Hash Column.new(v, **@options.merge( table: (parent if parent.is_a?(Table)), parent: self, context: nil, number: number)) else v end end else log_warn "#{type} has invalid property 'columns': expected array of Column" [] end unless object[:columns].all? {|v| v.is_a?(Column)} log_warn "#{type} has invalid property 'columns': expected array of Column" # Remove elements that aren't of the right types object[:columns] = object[:columns].select! {|v| v.is_a?(Column)} end end |
#foreign_keys_referencing(table) ⇒ Array<Hash>
List of foreign keys referencing the specified table
1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-tabular-52804f52e930/lib/rdf/tabular/metadata.rb', line 1541 def foreign_keys_referencing(table) Array(foreignKeys).select do |fk| reference = fk['reference'] if reference['resource'] ref = context.base.join(reference['resource']).to_s table.url == ref else # schemaReference ref = context.base.join(reference['schemaReference']).to_s table.tableSchema.id == ref end end end |
#foreignKeys=(value) ⇒ Object
1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-tabular-52804f52e930/lib/rdf/tabular/metadata.rb', line 1521 def foreignKeys=(value) object[:foreignKeys] = case value when Array then value else log_warn "#{type} has invalid property 'foreignKeys': expected array of ForeignKey" [] end unless object[:foreignKeys].all? {|v| v.is_a?(Hash)} log_warn "#{type} has invalid property 'foreignKeys': expected array of ForeignKey" # Remove elements that aren't of the right types object[:foreignKeys] = object[:foreignKeys].select! {|v| v.is_a?(Hash)} end end |
#to_atd ⇒ Object
Return Annotated Table representation
1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-tabular-52804f52e930/lib/rdf/tabular/metadata.rb', line 1555 def to_atd object.inject({ "@id" => (id.to_s if id), "@type" => "Schema", "columns" => Array(columns).map(&:to_atd), }) do |memo, (k, v)| memo[k.to_s] ||= v memo end.delete_if {|k,v| v.nil? || v.is_a?(Metadata)} end |