Class: RDF::Tabular::Column
- Defined in:
- lib/rdf/tabular/metadata.rb
Constant Summary collapse
- 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
-
#has_annotations? ⇒ Boolean
Does the Metadata or any descendant have any common properties.
-
#id ⇒ RDF::URI
Identifier for this Column, as an RFC7111 fragment.
-
#name ⇒ Object
Return or create a name for the column from titles, if it exists.
-
#number ⇒ Integer
Column number set on initialization.
-
#sourceNumber ⇒ Integer
Source Column number set on initialization.
-
#table ⇒ Table
Table containing this column (if any).
-
#to_atd ⇒ Object
Return Annotated Column representation.
Methods inherited from Metadata
#==, #[], #[]=, #base, #common_properties, #context, #datatype=, #describes_file?, #dialect, #dialect=, #each, #each_row, for_input, #initialize, #inspect, new, #normalize!, #normalize_jsonld, open, site_wide_config, #tableSchema=, #tables=, #to_json, #transformations=, #type, #valid?, #valid_natural_language_property?, #validate, #validate!, #verify_compatible!
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
1602 1603 1604 |
# File 'lib/rdf/tabular/metadata.rb', line 1602 def has_annotations? super || columns.any? {|c| c.has_annotations? } end |
#id ⇒ RDF::URI
Identifier for this Column, as an RFC7111 fragment
1638 1639 1640 1641 |
# File 'lib/rdf/tabular/metadata.rb', line 1638 def id; url = table ? table.url : RDF::URI("") url.to_s + "#col=#{self.sourceNumber}"; end |
#name ⇒ Object
Return or create a name for the column from titles, if it exists
1627 1628 1629 1630 1631 1632 1633 1634 |
# File 'lib/rdf/tabular/metadata.rb', line 1627 def name self[:name] || if titles && (ts = titles[context.default_language || 'und'] || titles[self.lang || 'und']) n = Array(ts).first n0 = RDF::URI.encode(n[0,1], /[^a-zA-Z0-9]/).encode("utf-8") n1 = RDF::URI.encode(n[1..-1], /[^\w\.]/).encode("utf-8") "#{n0}#{n1}" end || "_col.#{number}" end |
#number ⇒ Integer
Column number set on initialization
1587 1588 1589 |
# File 'lib/rdf/tabular/metadata.rb', line 1587 def number @options.fetch(:number, 0) end |
#sourceNumber ⇒ Integer
this is lazy evaluated to avoid dependencies on setting dialect vs. initializing columns
Source Column number set on initialization
1595 1596 1597 1598 |
# File 'lib/rdf/tabular/metadata.rb', line 1595 def sourceNumber skipColumns = table ? dialect.skipColumns.to_i : 0 number + skipColumns end |
#table ⇒ Table
Table containing this column (if any)
1583 |
# File 'lib/rdf/tabular/metadata.rb', line 1583 def table; @options[:table]; end |
#to_atd ⇒ Object
Return Annotated Column representation
1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 |
# File 'lib/rdf/tabular/metadata.rb', line 1644 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 |