class Spread2RDF::Mapping::Resource

Attributes

row_range[R]

Public Class Methods

new(sheet, parent, row_range) click to toggle source
Calls superclass method Spread2RDF::Mapping::Element::new
# File lib/spread2rdf/mapping/resource.rb, line 9
def initialize(sheet, parent, row_range)
  super(sheet, parent)
  @columns = {}
  @row_range = row_range
  map
end

Public Instance Methods

_children_()
Alias for: columns
column(name) click to toggle source
# File lib/spread2rdf/mapping/resource.rb, line 62
def column(name)
  @columns[column_schema(name).name]
end
column!(name) click to toggle source
# File lib/spread2rdf/mapping/resource.rb, line 66
def column!(name)
  column_schema = column_schema(name)
  @columns[column_schema.name] ||= case column_schema
    when Schema::Column      then Column.new(column_schema, self)
    when Schema::ColumnBlock then ColumnBlock.new(column_schema, self).map
  end
end
column_schema(name) click to toggle source
# File lib/spread2rdf/mapping/resource.rb, line 74
def column_schema(name)
  case name
    when Schema::Column, Schema::ColumnBlock then name
    when String, Symbol                      then schema.column(name)
    else raise ArgumentError
  end
end
columns() click to toggle source

Mapping::Element structure

# File lib/spread2rdf/mapping/resource.rb, line 57
def columns
  @columns.values
end
Also aliased as: _children_
map() click to toggle source
# File lib/spread2rdf/mapping/resource.rb, line 16
def map
  #puts "processing #{self} in #{row_range}"
  object_columns = parent.schema.columns - [parent.schema.subject_column]
  object_columns.each { |column| column!(column) }
  subject_description unless empty?
  self
end
resource_creation_value()
Alias for: subject_value
subject() click to toggle source
# File lib/spread2rdf/mapping/resource.rb, line 29
def subject
  @subject ||= create_resource
end

Private Instance Methods

subject_description() click to toggle source
# File lib/spread2rdf/mapping/resource.rb, line 44
def subject_description
  type = schema.subject_resource_type
  statement(subject, RDF.type, type) unless type.nil?
  if type == RDF::RDFS.Class &&
      super_class = schema.subject.try(:fetch, :sub_class_of, nil)
    statement(subject, RDF::RDFS.subClassOf, super_class)
  end
end
subject_value() click to toggle source
# File lib/spread2rdf/mapping/resource.rb, line 33
def subject_value
  cells = row_range.map do |row|
    parent.cell_value(row: row, column: schema.subject_column.coord).presence
  end.compact
  raise "no subject found for Resource in #{row_range} of #{sheet}" if cells.empty?
  raise "multiple subjects found for Resource in #{row_range} of #{sheet}: #{cells.inspect}" if cells.count > 1
  cells.first
end
Also aliased as: resource_creation_value