Class: RDF::Tabular::Column

Inherits:
Metadata show all
Defined in:
vendor/bundler/ruby/2.5.0/bundler/gems/rdf-tabular-e6dd10a784d9/lib/rdf/tabular/metadata.rb

Constant Summary

PROPERTIES =
{
  :@id         => :link,
  :@type       => :atomic,
  name:           :atomic,
  suppressOutput: :atomic,
  titles:         :natural_language,
  virtual:        :atomic,
}.freeze
DEFAULTS =
{
  suppressOutput:      false,
  virtual:             false,
}.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, #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, #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

#has_annotations?Boolean

Does the Metadata or any descendant have any common properties

Returns:

  • (Boolean)


1596
1597
1598
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-tabular-e6dd10a784d9/lib/rdf/tabular/metadata.rb', line 1596

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

#idRDF::URI

Identifier for this Column, as an RFC7111 fragment

Returns:



1632
1633
1634
1635
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-tabular-e6dd10a784d9/lib/rdf/tabular/metadata.rb', line 1632

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

#nameObject

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



1621
1622
1623
1624
1625
1626
1627
1628
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-tabular-e6dd10a784d9/lib/rdf/tabular/metadata.rb', line 1621

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

#numberInteger

Column number set on initialization

Returns:

  • (Integer)

    1-based colnum number



1581
1582
1583
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-tabular-e6dd10a784d9/lib/rdf/tabular/metadata.rb', line 1581

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



1589
1590
1591
1592
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-tabular-e6dd10a784d9/lib/rdf/tabular/metadata.rb', line 1589

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

#tableTable

Table containing this column (if any)

Returns:



1577
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-tabular-e6dd10a784d9/lib/rdf/tabular/metadata.rb', line 1577

def table; @options[:table]; end

#to_atdObject

Return Annotated Column representation



1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-tabular-e6dd10a784d9/lib/rdf/tabular/metadata.rb', line 1638

def to_atd
  object.inject({
    "@id" => id.to_s,
    "@type" => "Column",
    "table" => (table.id.to_s if table.id),
    "number" => self.number,
    "sourceNumber" => self.sourceNumber,
    "virtual" => self.virtual,
    "name" => self.name,
    "titles" => self.titles
  }) do |memo, (k, v)|
    memo[k.to_s] ||= v
    memo
  end.delete_if {|k,v| v.nil?}
end