Class: Spread2RDF::Mapping::Spreadsheet

Inherits:
Element
  • Object
show all
Defined in:
lib/spread2rdf/mapping/spreadsheet.rb

Instance Attribute Summary collapse

Attributes inherited from Element

#parent, #schema

Instance Method Summary collapse

Methods inherited from Element

#empty?, #graph, #to_s

Constructor Details

#initialize(schema, filename) ⇒ Spreadsheet

Returns a new instance of Spreadsheet.



7
8
9
10
11
12
# File 'lib/spread2rdf/mapping/spreadsheet.rb', line 7

def initialize(schema, filename)
  super(schema, nil)
  @worksheets = {}
  @input_file = filename
  ROO.load(filename)
end

Instance Attribute Details

#input_fileObject (readonly)

Returns the value of attribute input_file.



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

def input_file
  @input_file
end

Instance Method Details

#mapObject



14
15
16
17
18
19
20
# File 'lib/spread2rdf/mapping/spreadsheet.rb', line 14

def map
  schema.sorted_worksheets.each do |worksheet_schema|
    next unless ROO.roo.sheets.include? worksheet_schema.source_name
    worksheet!(worksheet_schema)
  end
  self
end

#spreadsheetObject

Mapping::Element structure



33
34
35
# File 'lib/spread2rdf/mapping/spreadsheet.rb', line 33

def spreadsheet
  self
end

#worksheet(name) ⇒ Object



42
43
44
# File 'lib/spread2rdf/mapping/spreadsheet.rb', line 42

def worksheet(name)
  @worksheets[worksheet_schema(name).name]
end

#worksheet!(name) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/spread2rdf/mapping/spreadsheet.rb', line 46

def worksheet!(name)
  worksheet_schema = worksheet_schema(name)
  @worksheets[worksheet_schema.name] || begin
    @worksheets[worksheet_schema.name] = mapping =
        Mapping::Worksheet.new(worksheet_schema, self)
    mapping.map
  end
end

#worksheet_schema(name) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/spread2rdf/mapping/spreadsheet.rb', line 22

def worksheet_schema(name)
  case name
    when Schema::Worksheet then name
    when String, Symbol    then schema.worksheet[name]
    else raise ArgumentError
  end
end

#worksheetsObject Also known as: _children_



37
38
39
# File 'lib/spread2rdf/mapping/spreadsheet.rb', line 37

def worksheets
  @worksheets.values
end