Class: Spread2RDF::Mapping::Cell

Inherits:
Element
  • Object
show all
Defined in:
lib/spread2rdf/mapping/cell.rb,
lib/spread2rdf/mapping/default_cell_mappings.rb

Defined Under Namespace

Modules: Default

Instance Attribute Summary collapse

Attributes inherited from Element

#parent, #schema

Instance Method Summary collapse

Methods inherited from Element

#graph, #to_s

Constructor Details

#initialize(sheet, parent, row) ⇒ Cell

Returns a new instance of Cell.



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

def initialize(sheet, parent, row)
  super(sheet, parent)
  @row = row
  map
end

Instance Attribute Details

#rowObject (readonly)

Returns the value of attribute row.



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

def row
  @row
end

Instance Method Details

#_children_Object

Element#children



126
127
128
# File 'lib/spread2rdf/mapping/cell.rb', line 126

def _children_
  nil
end

#coordObject



20
21
22
# File 'lib/spread2rdf/mapping/cell.rb', line 20

def coord
  Coord[column: schema.coord, row: row]
end

#empty?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/spread2rdf/mapping/cell.rb', line 32

def empty?
  value.blank?
end

#mapObject



16
17
18
# File 'lib/spread2rdf/mapping/cell.rb', line 16

def map
  exec(&schema.block) unless empty?
end

#objectObject



28
29
30
# File 'lib/spread2rdf/mapping/cell.rb', line 28

def object
  @object ||= value && map_to_object(value)
end

#object_of_column(name) ⇒ Object



110
111
112
113
114
115
# File 'lib/spread2rdf/mapping/cell.rb', line 110

def object_of_column(name)
  other_column = resource.column!(name)
  raise "couldn't find column #{name} when mapping #{self}" if
      other_column.nil?
  other_column.cell!(row).object
end

#valueObject



24
25
26
# File 'lib/spread2rdf/mapping/cell.rb', line 24

def value
  @value ||= worksheet.cell_value(coord)
end

#value_of_column(name) ⇒ Object

for the DSL for column statement blocks



102
103
104
105
106
107
108
# File 'lib/spread2rdf/mapping/cell.rb', line 102

def value_of_column(name)
  sheet_schema = parent.parent.schema
  other_column = sheet_schema.column(name)
  raise "couldn't find column #{name} when mapping #{self}" if
      other_column.nil?
  worksheet.cell_value(column: other_column.coord, row: row)
end