Class: PublishMyData::Theme

Inherits:
Object
  • Object
show all
Includes:
BasicFeatures, Tripod::Resource
Defined in:
app/models/publish_my_data/theme.rb

Overview

A theme for datasets

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BasicFeatures

#eager_load!, #in_domain?

Class Method Details

.by_slug(slug) ⇒ Object



13
14
15
# File 'app/models/publish_my_data/theme.rb', line 13

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

.theme_graphObject



9
10
11
# File 'app/models/publish_my_data/theme.rb', line 9

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

Instance Method Details

#datasets_countObject



23
24
25
# File 'app/models/publish_my_data/theme.rb', line 23

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

#datasets_query_strObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/models/publish_my_data/theme.rb', line 27

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

#to_paramObject



57
58
59
# File 'app/models/publish_my_data/theme.rb', line 57

def to_param
  self.slug
end