Class: Spread2RDF::Schema::Column

Inherits:
Element
  • Object
show all
Includes:
ResourceCreation, StatementMapping
Defined in:
lib/spread2rdf/schema/column.rb

Instance Attribute Summary collapse

Attributes inherited from Element

#block, #parent

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ResourceCreation

#resource_creation_mode, #resource_creation_namespace

Methods included from StatementMapping

#inverse_mode, #restriction_mode, #statement_mapping_mode

Methods inherited from Element

#initialize, #name, #source_name, #worksheet

Methods included from Attributes

#init_attributes, #inspect, #update_attributes

Constructor Details

This class inherits a constructor from Spread2RDF::Schema::Element

Instance Attribute Details

#coordObject (readonly)

this is set by Worksheet#index_columns!



47
48
49
# File 'lib/spread2rdf/schema/column.rb', line 47

def coord
  @coord
end

Class Method Details

.normalize_attributes(values) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# 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

Instance Method Details

#cell_mappingObject



72
73
74
# File 'lib/spread2rdf/schema/column.rb', line 72

def cell_mapping
  object if object.is_a?(Proc)
end

#object_mapping_modeObject



55
56
57
58
59
60
61
62
63
64
65
66
# 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_attributesObject



68
69
70
# File 'lib/spread2rdf/schema/column.rb', line 68

def resource_creation_attributes
  object
end

#to_sObject



51
52
53
# File 'lib/spread2rdf/schema/column.rb', line 51

def to_s
  "#{super} of #{sheet}"
end