Sha256: 8bbfc60e786acda3e8febd786a9470609eeb5c8fada7aed3b699a7f26d63b774

Contents?: true

Size: 1.76 KB

Versions: 1

Compression:

Stored size: 1.76 KB

Contents

module Spread2RDF
  class Spreadsheet
    class SubSheet
      class MappingContext < Sheet::MappingContext

        self.attributes = {
        }

        alias sub_sheet element
        alias column_block element

        private

        ##########################################################################
        # Statement mapping
        # TODO: Duplication Column::MappingContext ! Share it ?

        def statement_mapping_mode
          case
            when column_block.statement == :none then :ignore
            when column_block.statement == :none then :ignore
            when column_block.predicate.nil?     then :ignore
            when restriction_mode                then :restriction
            else                                      :default
          end
        end

        def restriction_mode
          restriction_mode = column_block.statement
          case restriction_mode
            when :restriction then RDF::OWL.hasValue
            when Hash         then restriction_mode[:restriction]
            else nil
          end
        end

        def statements_to_object
          case statement_mapping_mode
            when :default
              statement(parent_context.subject, column_block.predicate, subject)
            when :restriction
              restriction_class = RDF::Node.new
              statements(
                  [ parent_context.subject, RDF::RDFS.subClassOf, restriction_class ],
                  [ restriction_class, RDF.type, RDF::OWL.Restriction ],
                  [ restriction_class, RDF::OWL.onProperty, column_block.predicate ],
                  [ restriction_class, restriction_mode, subject ]
              )
          end
        end

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spread2rdf-0.0.1pre.1 lib/spread2rdf/spreadsheet/sub_sheet_mapping_context.rb