Sha256: af37fccc981ac6b453fc290ea7b937e43890bc9e56df1f5ad101a65dd341c5fc

Contents?: true

Size: 1.6 KB

Versions: 39

Compression:

Stored size: 1.6 KB

Contents

module PublishMyData
  # A theme for datasets
  class Theme

    include Tripod::Resource
    include BasicFeatures

    class << self
      def theme_graph
        RDF::URI.new("http://#{PublishMyData.local_domain}/graph/concept-scheme/themes")
      end

      def by_slug(slug)
        Theme.where("?uri <#{RDF::SKOS.notation}> '#{slug}'").first
      end
    end

    rdf_type RDF::SITE.Theme
    graph_uri Theme.theme_graph

    field :slug, RDF::SKOS.notation

    def datasets_count
      PublishMyData::SparqlQuery.new(datasets_query_str).count
    end

    def datasets_query_str
      # this is similar to the deprecation_last_query_str, but with a theme restriction
      "
      SELECT ?uri where {
        # this bit is all the non-deprecated ones
        {
          SELECT * WHERE {
            ?uri a <http://publishmydata.com/def/dataset#Dataset> .
            ?uri <#{RDF::DCAT.theme}> <#{self.uri.to_s}> . # limit to this theme
            ?uri <#{RDF::DC.title}> ?title . # select title so we can order
            MINUS {
              ?uri a <http://publishmydata.com/def/dataset#DeprecatedDataset>
            }
          }
          ORDER BY ?title
        }
        UNION
        # this bit is all the deprecated ones
        {
          SELECT * WHERE {
            ?uri a <http://publishmydata.com/def/dataset#DeprecatedDataset> .
            ?uri <#{RDF::DCAT.theme}> <#{self.uri.to_s}> . # limit to this theme
            ?uri <#{RDF::DC.title}> ?title . # select title so we can order
          }
          ORDER BY ?title
        }
      }
      "
    end

    def to_param
      self.slug
    end

  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
publish_my_data-1.3.25 app/models/publish_my_data/theme.rb
publish_my_data-1.3.24 app/models/publish_my_data/theme.rb
publish_my_data-1.3.23 app/models/publish_my_data/theme.rb
publish_my_data-1.3.22 app/models/publish_my_data/theme.rb
publish_my_data-1.3.21 app/models/publish_my_data/theme.rb
publish_my_data-1.3.20 app/models/publish_my_data/theme.rb
publish_my_data-1.3.19 app/models/publish_my_data/theme.rb
publish_my_data-1.3.18 app/models/publish_my_data/theme.rb
publish_my_data-1.3.17 app/models/publish_my_data/theme.rb
publish_my_data-1.3.16 app/models/publish_my_data/theme.rb
publish_my_data-1.3.15 app/models/publish_my_data/theme.rb
publish_my_data-1.3.14 app/models/publish_my_data/theme.rb
publish_my_data-1.3.13 app/models/publish_my_data/theme.rb
publish_my_data-1.3.12 app/models/publish_my_data/theme.rb
publish_my_data-1.3.11 app/models/publish_my_data/theme.rb
publish_my_data-1.3.10 app/models/publish_my_data/theme.rb
publish_my_data-1.3.9 app/models/publish_my_data/theme.rb
publish_my_data-1.3.8 app/models/publish_my_data/theme.rb
publish_my_data-1.3.7 app/models/publish_my_data/theme.rb
publish_my_data-1.3.6 app/models/publish_my_data/theme.rb