lib/spread2rdf/schema/column.rb in spread2rdf-0.0.2 vs lib/spread2rdf/schema/column.rb in spread2rdf-0.1.0
- old
+ new
@@ -7,9 +7,43 @@
predicate: nil,
object: nil,
statement: nil
}
+ def self.normalize_attributes(values)
+ if object = values[:object]
+ case
+ when object.is_a?(Proc) then # nothing
+ when !(from = object.delete(:from_worksheet) ||
+ object.delete(:from_sheet)).nil?
+ object[:from] = { worksheet: from.to_sym }
+ when !(from = object.delete(:from_data_source)).nil?
+ object[:from] = { data_source: resolve_data_sources(from) }
+ when !(from = object[:from]).nil?
+ case from
+ when Symbol then object[:from] = { worksheet: from }
+ when String then object[:from] = { data_source: resolve_data_sources(from) }
+ when Hash
+ from[:data_source] = resolve_data_sources(from[:data_source]) if from.include?(:data_source)
+ end
+ end
+ end
+ values
+ end
+
+ def self.resolve_data_sources(data_sources)
+ return [data_sources] unless data_sources.is_a? Array
+ data_sources.map do |data_source|
+ case
+ when (uri = data_source).is_a?(RDF::URI) || (uri = RDF::URI.new(data_source)).valid?
+ raise NotImplementedError, "resolving of uris is not implemented yet"
+ when data_source.is_a?(String) && !(file = File.in_path(data_source)).nil?
+ RDF::Graph.load file
+ else puts "WARNING: couldn't resolve data source #{data_source}"
+ end
+ end.compact
+ end
+
attr_reader :coord # this is set by Worksheet#index_columns!
alias sheet parent
def to_s