Class: Spread2RDF::Mapping::Resource

Inherits:
Element
  • Object
show all
Includes:
ResourceCreation
Defined in:
lib/spread2rdf/mapping/resource.rb

Instance Attribute Summary collapse

Attributes inherited from Element

#parent, #schema

Instance Method Summary collapse

Methods included from ResourceCreation

#create_resource

Methods inherited from Element

#empty?, #graph, #to_s

Constructor Details

#initialize(sheet, parent, row_range) ⇒ Resource

Returns a new instance of Resource.



9
10
11
12
13
14
# File 'lib/spread2rdf/mapping/resource.rb', line 9

def initialize(sheet, parent, row_range)
  super(sheet, parent)
  @columns = {}
  @row_range = row_range
  map
end

Instance Attribute Details

#row_rangeObject (readonly)

Returns the value of attribute row_range.



5
6
7
# File 'lib/spread2rdf/mapping/resource.rb', line 5

def row_range
  @row_range
end

Instance Method Details

#column(name) ⇒ Object



62
63
64
# File 'lib/spread2rdf/mapping/resource.rb', line 62

def column(name)
  @columns[column_schema(name).name]
end

#column!(name) ⇒ Object



66
67
68
69
70
71
72
# 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) ⇒ Object



74
75
76
77
78
79
80
# 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

#columnsObject Also known as: _children_

Mapping::Element structure



57
58
59
# File 'lib/spread2rdf/mapping/resource.rb', line 57

def columns
  @columns.values
end

#mapObject



16
17
18
19
20
21
22
# 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

#subjectObject



29
30
31
# File 'lib/spread2rdf/mapping/resource.rb', line 29

def subject
  @subject ||= create_resource
end