class Spread2RDF::Mapping::Sheet

Attributes

_children_[R]
resources[R]

Public Class Methods

new(sheet, parent) click to toggle source
Calls superclass method Spread2RDF::Mapping::Element::new
# File lib/spread2rdf/mapping/sheet.rb, line 5
def initialize(sheet, parent)
  super
  @resources = []
end

Public Instance Methods

cell(coord)
Alias for: cell_value
cell_value(coord) click to toggle source

Roo helper

# File lib/spread2rdf/mapping/sheet.rb, line 67
def cell_value(coord)
  value = ROO.cell(coord, schema.worksheet.source_name)
  value = value.strip if value.is_a? String
  value
end
Also aliased as: cell
map() click to toggle source
# File lib/spread2rdf/mapping/sheet.rb, line 10
def map
  #puts "processing #{self} in #{row_range}"
  return [] if row_range.nil? or schema.columns.empty?
  rows_per_resource.each do |resource_range|
    @resources << Mapping::Resource.new(schema, self, resource_range)
  end
  self
end
resource_by_index(index) click to toggle source
# File lib/spread2rdf/mapping/sheet.rb, line 60
def resource_by_index(index)
  @resources[index]
end
resource_by_row(row) click to toggle source
# File lib/spread2rdf/mapping/sheet.rb, line 55
def resource_by_row(row)
  index = rows_per_resource.find_index { |range| range.include? row }
  resource_by_index(index)
end
roo(&block) click to toggle source
# File lib/spread2rdf/mapping/sheet.rb, line 74
def roo(&block)
  ROO.roo(schema.worksheet.source_name, &block)
end
rows_per_resource() click to toggle source
# File lib/spread2rdf/mapping/sheet.rb, line 19
def rows_per_resource
  return [] if row_range.nil?
  @rows_per_resource ||= begin
    rows = if fix_row_count = schema.fix_row_count_per_resource
             row_range.find_all do |row|
               (row - row_range.begin) % fix_row_count == 0
             end
           else
             subject_column_coord = schema.subject_column.try(:coord)
             raise "no subject column for #{self}" if subject_column_coord.blank?
             row_range.find_all do |row|
               not cell(row: row, column: subject_column_coord).blank?
             end
           end
    rows_per_resource = []
    rows.each_with_index do |first_row, i|
      last_row = (i+1 == rows.count ? row_range.end : rows[i+1]-1)
      rows_per_resource << Range.new(first_row, last_row)
    end
    rows_per_resource
  end
end
worksheet() click to toggle source

Mapping::Element structure

# File lib/spread2rdf/mapping/sheet.rb, line 45
def worksheet
  return self if self.is_a? Worksheet
  parent = self.parent
  parent = parent.parent until parent.is_a? Worksheet or parent.nil?
  parent
end