Class: Spread2RDF::Schema::Sheet

Inherits:
Element
  • Object
show all
Defined in:
lib/spread2rdf/schema/sheet.rb,
lib/spread2rdf/schema/sheet_dsl.rb

Direct Known Subclasses

ColumnBlock, Worksheet

Defined Under Namespace

Classes: DSL

Instance Attribute Summary

Attributes inherited from Element

#block, #parent

Instance Method Summary collapse

Methods inherited from Element

#name, #source_name, #to_s, #worksheet

Methods included from Attributes

#init_attributes, #inspect, #update_attributes

Constructor Details

#initialize(parent, attr = {}, &block) ⇒ Sheet

Returns a new instance of Sheet.



11
12
13
14
15
# File 'lib/spread2rdf/schema/sheet.rb', line 11

def initialize(parent, attr = {}, &block)
  super
  @column = {}
  @column_index = {}
end

Instance Method Details

#column_by_coord(coord) ⇒ Object



21
22
23
24
# File 'lib/spread2rdf/schema/sheet.rb', line 21

def column_by_coord(coord)
  coord = Roo::Base.number_to_letter(coord) if coord.is_a? Integer
  @column_index[coord]
end

#column_by_name(name = nil) ⇒ Object Also known as: column



26
27
28
29
30
# File 'lib/spread2rdf/schema/sheet.rb', line 26

def column_by_name(name = nil)
  return @column if name.nil?
  name = name.to_sym
  @column[name] or ( parent.is_a?(Sheet) and parent.column(name) ) or nil
end

#column_rangeObject



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

def column_range
  first = columns.first.coord
  first = first.begin if first.is_a? Range
  last = columns.last.coord
  last = last.end if last.is_a? Range
  first .. last
end

#columnsObject



33
34
35
# File 'lib/spread2rdf/schema/sheet.rb', line 33

def columns
  @column.values
end

#each_column(&block) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/spread2rdf/schema/sheet.rb', line 45

def each_column(&block)
  columns.each do |column|
    if column.is_a? ColumnBlock
      column.each_column(&block)
    else
      yield column
    end
  end
end

#fix_row_count_per_resourceObject



60
61
62
# File 'lib/spread2rdf/schema/sheet.rb', line 60

def fix_row_count_per_resource
  row_count_per_resource or ( !subject_column && 1 ) or nil
end

#start_coordObject



17
18
19
# File 'lib/spread2rdf/schema/sheet.rb', line 17

def start_coord
  Coord[start]
end

#subject_columnObject



55
56
57
58
# File 'lib/spread2rdf/schema/sheet.rb', line 55

def subject_column
  column_name = self.subject.try(:fetch, :column, nil) || :uri
  @column[column_name]
end

#subject_mapping_modeObject



64
65
66
67
68
69
70
71
# File 'lib/spread2rdf/schema/sheet.rb', line 64

def subject_mapping_mode
  case
    when ( subject.try(:fetch, :uri, nil) || subject ) == :bnode
      :bnode
    else
      :from_column
  end
end

#subject_namespaceObject



73
74
75
76
77
# File 'lib/spread2rdf/schema/sheet.rb', line 73

def subject_namespace
  subject_namespace_name =
      subject.try(:fetch, :uri, nil).try(:fetch, :namespace, nil)
  Namespace.resolve_to_namespace(subject_namespace_name)
end

#subject_resource_typeObject



79
80
81
82
83
# File 'lib/spread2rdf/schema/sheet.rb', line 79

def subject_resource_type
  subject.try(:fetch, :type, nil) or
      (subject.try(:fetch, :sub_class_of, nil) && RDF::RDFS.Class) or
      nil
end