Class: RDF::Tabular::Column

Inherits:
Metadata show all
Defined in:
lib/rdf/tabular/metadata.rb

Constant Summary collapse

PROPERTIES =
{
  :@id         => :link,
  :@type       => :atomic,
  name:           :atomic,
  suppressOutput: :atomic,
  title:          :natural_language,
  required:       :atomic,
  virtual:        :atomic,
}.freeze
REQUIRED =
[].freeze

Constants inherited from Metadata

Metadata::DATATYPES, Metadata::INHERITED_PROPERTIES, Metadata::LOCAL_CONTEXT, Metadata::NAME_SYNTAX

Instance Attribute Summary

Attributes inherited from Metadata

#filenames, #object, #parent, #url

Instance Method Summary collapse

Methods inherited from Metadata

#==, #[], #[]=, #base, #common_properties, #context, #dialect, #dialect=, #each, #each_row, #errors, for_input, #initialize, #inspect, #merge, #merge!, new, #normalize!, #normalize_datatype, #normalize_jsonld, open, #to_json, #type, #valid?, #valid_inherited_property?, #valid_natural_language_property?, #validate!

Methods included from Utils

debug, #depth

Constructor Details

This class inherits a constructor from RDF::Tabular::Metadata

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

Logic for accessing elements as accessors



1542
1543
1544
1545
1546
1547
1548
# File 'lib/rdf/tabular/metadata.rb', line 1542

def method_missing(method, *args)
  if INHERITED_PROPERTIES.has_key?(method.to_sym)
    inherited_property_value(method.to_sym)
  else
    PROPERTIES.has_key?(method.to_sym) ? object[method.to_sym] : super
  end
end

Instance Method Details

#has_annotations?Boolean

Does the Metadata or any descendant have any common properties

Returns:

  • (Boolean)


1493
1494
1495
# File 'lib/rdf/tabular/metadata.rb', line 1493

def has_annotations?
  super || columns.any? {|c| c.has_annotations? }
end

#idRDF::URI

Identifier for this Column, as an RFC7111 fragment

Returns:

  • (RDF::URI)


1521
1522
1523
1524
# File 'lib/rdf/tabular/metadata.rb', line 1521

def id;
  url = table ? table.url : RDF::URI("")
  url + "#col=#{self.sourceNumber}";
end

#nameObject

Return or create a name for the column from title, if it exists



1510
1511
1512
1513
1514
1515
1516
1517
# File 'lib/rdf/tabular/metadata.rb', line 1510

def name
  object[:name] ||= if title && (ts = title[context.default_language || 'und'])
    n = Array(ts).first
    n0 = URI.encode(n[0,1], /[^a-zA-Z0-9]/)
    n1 = URI.encode(n[1..-1], /[^\w\.]/)
    "#{n0}#{n1}"
  end || "_col.#{number}"
end

#numberInteger

Column number set on initialization

Returns:

  • (Integer)

    1-based colnum number



1478
1479
1480
# File 'lib/rdf/tabular/metadata.rb', line 1478

def number
  @options.fetch(:number, 0)
end

#sourceNumberInteger

Note:

this is lazy evaluated to avoid dependencies on setting dialect vs. initializing columns

Source Column number set on initialization

Returns:

  • (Integer)

    1-based colnum number



1486
1487
1488
1489
# File 'lib/rdf/tabular/metadata.rb', line 1486

def sourceNumber
  skipColumns = table ? (dialect.skipColumns.to_i + dialect.headerColumnCount.to_i) : 0
  number + skipColumns
end

#tableTable

Table containing this column (if any)

Returns:



1474
# File 'lib/rdf/tabular/metadata.rb', line 1474

def table; @options[:table]; end

#to_atdObject

Return Annotated Column representation



1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
# File 'lib/rdf/tabular/metadata.rb', line 1527

def to_atd
  {
    "@id" => id,
    "@type" => "Column",
    "table" => (table.id if table),
    "number" => self.number,
    "sourceNumber" => self.sourceNumber,
    "cells" => [],
    "virtual" => self.virtual,
    "name" => self.name,
    "title" => self.title
  }
end