Sha256: 6010e59517069b0adeeb3670d3cab4aba45340e7e38cab461aab26b25895c91c

Contents?: true

Size: 1.29 KB

Versions: 35

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module LinkedRails
  class Ontology
    class Base
      include ActiveModel::Model
      include LinkedRails::Model
      attr_accessor :iri

      def data
        data = []
        iri.try(:each_statement) do |statement|
          next unless include_data_statement?(statement)

          statement.graph_name = ::RDF::Serializers.config.default_graph
          data << statement
        end
        data
      end

      def description
        @description ||= LinkedRails.translations(
          -> { LinkedRails.translate(self.class.translation_key, :description, iri) }
        )
      end

      def image
        @image ||= RDF::URI("http://fontawesome.io/icon/#{icon}") if icon
      end

      def label
        @label ||= LinkedRails.translations(
          -> { LinkedRails.translate(self.class.translation_key, :label, iri) }
        )
      end

      private

      def icon
        @icon ||= LinkedRails.translate(self.class.translation_key, :icon, iri)
      end

      def include_data_statement?(statement)
        return false if statement.subject.node? || statement.object.node?

        statement.predicate != Vocab.rdfs.label &&
          statement.predicate != Vocab.rdfs.range &&
          statement.predicate != Vocab.rdfs.domain
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
linked_rails-0.0.4.pre.g3aeec2263 app/models/linked_rails/ontology/base.rb
linked_rails-0.0.4.pre.gacd5f04d4 app/models/linked_rails/ontology/base.rb
linked_rails-0.0.4.pre.gb0b6aea40 app/models/linked_rails/ontology/base.rb
linked_rails-0.0.4.pre.g792a1b887 app/models/linked_rails/ontology/base.rb
linked_rails-0.0.4.pre.g58af47992 app/models/linked_rails/ontology/base.rb
linked_rails-0.0.4.pre.g0ec6e30ca app/models/linked_rails/ontology/base.rb
linked_rails-0.0.4.pre.g9e3bcac55 app/models/linked_rails/ontology/base.rb
linked_rails-0.0.4.pre.g222bfeeca app/models/linked_rails/ontology/base.rb
linked_rails-0.0.4.pre.gb254a2893 app/models/linked_rails/ontology/base.rb
linked_rails-0.0.4.pre.g2c6c26e86 app/models/linked_rails/ontology/base.rb
linked_rails-0.0.4.pre.ge881247c3 app/models/linked_rails/ontology/base.rb
linked_rails-0.0.4.pre.gfabf7e9f5 app/models/linked_rails/ontology/base.rb
linked_rails-0.0.4.pre.g8c045be3a app/models/linked_rails/ontology/base.rb
linked_rails-0.0.4.pre.g8d7195543 app/models/linked_rails/ontology/base.rb
linked_rails-0.0.4.pre.gfe77aae19 app/models/linked_rails/ontology/base.rb
linked_rails-0.0.4.pre.gc866c1806 app/models/linked_rails/ontology/base.rb
linked_rails-0.0.4.pre.g3e8f5731a app/models/linked_rails/ontology/base.rb
linked_rails-0.0.4.pre.g58e27be7f app/models/linked_rails/ontology/base.rb
linked_rails-0.0.4.pre.g96885856b app/models/linked_rails/ontology/base.rb
linked_rails-0.0.4.pre.g1faca9643 app/models/linked_rails/ontology/base.rb