Class: Spread2RDF::Schema::Spreadsheet
- Inherits:
-
Object
- Object
- Spread2RDF::Schema::Spreadsheet
- Defined in:
- lib/spread2rdf/schema/spreadsheet.rb,
lib/spread2rdf/schema/spreadsheet_dsl.rb
Defined Under Namespace
Classes: DSL
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#worksheet ⇒ Object
readonly
Returns the value of attribute worksheet.
Instance Method Summary collapse
-
#initialize(name, &block) ⇒ Spreadsheet
constructor
A new instance of Spreadsheet.
- #map(input_file) ⇒ Object
- #sorted_worksheets ⇒ Object
- #spreadsheet ⇒ Object
- #worksheets ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ Spreadsheet
Returns a new instance of Spreadsheet.
8 9 10 11 12 |
# File 'lib/spread2rdf/schema/spreadsheet.rb', line 8 def initialize(name, &block) @name = name @worksheet = {} @schema_spec = block end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/spread2rdf/schema/spreadsheet.rb', line 5 def name @name end |
#worksheet ⇒ Object (readonly)
Returns the value of attribute worksheet.
6 7 8 |
# File 'lib/spread2rdf/schema/spreadsheet.rb', line 6 def worksheet @worksheet end |
Instance Method Details
#map(input_file) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/spread2rdf/schema/spreadsheet.rb', line 39 def map(input_file) mapping = Mapping::Spreadsheet.new(self, input_file) DSL.new(self, input_file).instance_exec(&@schema_spec) worksheets.each { |worksheet| worksheet.init } mapping.map mapping end |
#sorted_worksheets ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/spread2rdf/schema/spreadsheet.rb', line 22 def sorted_worksheets unsorted_worksheets, sorted_worksheets = worksheets, [] unsorted_worksheets.reject! do |worksheet| worksheet.columns.empty? and sorted_worksheets << worksheet end while not unsorted_worksheets.empty? independent = unsorted_worksheets.find_index { |worksheet| unsorted_worksheets.none? do |other_worksheet| worksheet.depends_on? other_worksheet end } raise "schema contains cyclic dependencies" if independent.nil? sorted_worksheets << unsorted_worksheets.delete_at(independent) end sorted_worksheets end |
#spreadsheet ⇒ Object
14 15 16 |
# File 'lib/spread2rdf/schema/spreadsheet.rb', line 14 def spreadsheet self end |
#worksheets ⇒ Object
18 19 20 |
# File 'lib/spread2rdf/schema/spreadsheet.rb', line 18 def worksheets @worksheet.values end |