class Spread2RDF::Schema::Column

Attributes

coord[R]

Public Class Methods

normalize_attributes(values) click to toggle source
# File lib/spread2rdf/schema/column.rb, line 13
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
resolve_data_sources(data_sources) click to toggle source
# File lib/spread2rdf/schema/column.rb, line 34
def self.resolve_data_sources(data_sources)
  data_sources = [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

Public Instance Methods

cell_mapping() click to toggle source
# File lib/spread2rdf/schema/column.rb, line 72
def cell_mapping
  object if object.is_a?(Proc)
end
object_mapping_mode() click to toggle source
# File lib/spread2rdf/schema/column.rb, line 55
def object_mapping_mode
  case
    when object.nil?              then :to_string
    when object.is_a?(Proc)       then :custom
    when !object[:uri].nil?       then :new_resource
    when !object[:from].nil?      then :resource_ref
    when !object[:language].nil?  then :to_string
    when !object[:datatype].nil?  then :to_string
    else
      raise "mapping specification error: don't know how to map #{self}"
  end
end
resource_creation_attributes() click to toggle source
# File lib/spread2rdf/schema/column.rb, line 68
def resource_creation_attributes
  object
end
to_s() click to toggle source
# File lib/spread2rdf/schema/column.rb, line 51
def to_s
  "#{super} of #{sheet}"
end