Class: Spread2RDF::Mapping::Sheet
- Defined in:
- lib/spread2rdf/mapping/sheet.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#resources ⇒ Object
(also: #_children_)
readonly
Returns the value of attribute resources.
Attributes inherited from Element
Instance Method Summary collapse
-
#cell_value(coord) ⇒ Object
(also: #cell)
Roo helper.
-
#initialize(sheet, parent) ⇒ Sheet
constructor
A new instance of Sheet.
- #map ⇒ Object
- #resource_by_index(index) ⇒ Object
- #resource_by_row(row) ⇒ Object
- #roo(&block) ⇒ Object
- #rows_per_resource ⇒ Object
-
#worksheet ⇒ Object
Mapping::Element structure.
Methods inherited from Element
Constructor Details
#initialize(sheet, parent) ⇒ Sheet
Returns a new instance of Sheet.
5 6 7 8 |
# File 'lib/spread2rdf/mapping/sheet.rb', line 5 def initialize(sheet, parent) super @resources = [] end |
Instance Attribute Details
#resources ⇒ Object (readonly) Also known as: _children_
Returns the value of attribute resources.
52 53 54 |
# File 'lib/spread2rdf/mapping/sheet.rb', line 52 def resources @resources end |
Instance Method Details
#cell_value(coord) ⇒ Object Also known as: cell
Roo helper
67 68 69 70 71 |
# 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 |
#map ⇒ Object
10 11 12 13 14 15 16 17 |
# 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) ⇒ Object
60 61 62 |
# File 'lib/spread2rdf/mapping/sheet.rb', line 60 def resource_by_index(index) @resources[index] end |
#resource_by_row(row) ⇒ Object
55 56 57 58 |
# 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) ⇒ Object
74 75 76 |
# File 'lib/spread2rdf/mapping/sheet.rb', line 74 def roo(&block) ROO.roo(schema.worksheet.source_name, &block) end |
#rows_per_resource ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# 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 |