Class: Spread2RDF::Mapping::Element

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/spread2rdf/mapping/element.rb

Direct Known Subclasses

Cell, Column, Resource, Sheet, Spreadsheet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema, parent) ⇒ Element

Returns a new instance of Element.



13
14
15
16
17
# File 'lib/spread2rdf/mapping/element.rb', line 13

def initialize(schema, parent)
  @graph = RDF::Repository.new
  @schema = schema
  @parent = parent
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



9
10
11
# File 'lib/spread2rdf/mapping/element.rb', line 9

def parent
  @parent
end

#schemaObject (readonly)

Returns the value of attribute schema.



8
9
10
# File 'lib/spread2rdf/mapping/element.rb', line 8

def schema
  @schema
end

Instance Method Details

#_children_Object

children

Raises:

  • (NotImplementedError)


26
27
28
# File 'lib/spread2rdf/mapping/element.rb', line 26

def _children_
  raise NotImplementedError, 'subclasses must implement this method'
end

#empty?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/spread2rdf/mapping/element.rb', line 30

def empty?
  _children_.empty? or _children_.all?(&:empty?)
end

#graphObject Also known as: to_rdf

RDF graph



37
38
39
40
41
42
43
# File 'lib/spread2rdf/mapping/element.rb', line 37

def graph
  if _children_
    _children_.inject(@graph.clone) { |graph, child| graph << child.graph }
  else
    @graph
  end
end

#to_sObject



19
20
21
# File 'lib/spread2rdf/mapping/element.rb', line 19

def to_s
  "#{self.class.name.split('::').last}-mapping of #{schema}"
end