Class: RDF::Tabular::Schema

Inherits:
Metadata show all
Defined in:
vendor/bundler/ruby/2.5.0/bundler/gems/rdf-tabular-b6c38e4731e8/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

Instance Attribute Summary

Attributes inherited from Metadata

#filenames, #id, #object, #parent, #url

Instance Method Summary collapse

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



1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-tabular-b6c38e4731e8/lib/rdf/tabular/metadata.rb', line 1484

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

Parameters:

Returns:



1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-tabular-b6c38e4731e8/lib/rdf/tabular/metadata.rb', line 1533

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



1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-tabular-b6c38e4731e8/lib/rdf/tabular/metadata.rb', line 1513

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_atdObject

Return Annotated Table representation



1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-tabular-b6c38e4731e8/lib/rdf/tabular/metadata.rb', line 1547

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