Module: DataKitten::PublishingFormats::CKAN

Defined in:
lib/data_kitten/publishing_formats/ckan.rb

Instance Method Summary collapse

Instance Method Details

#contributorsObject



130
131
132
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 130

def contributors
  extract_agent('author', 'author_email')
end

#data_titleObject

The human-readable title of the dataset.

See Also:



69
70
71
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 69

def data_title
  .lookup("title")
end

#descriptionObject

A brief description of the dataset



76
77
78
79
80
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 76

def description
  .lookup("notes") || .lookup("description")
rescue 
  nil
end

#distributionsObject

A list of distributions, referred to as resources by Datapackage.



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 151

def distributions
  distributions = []
  .lookup("resources").each do |resource|
    distribution = {
      :title => resource["description"],
      :accessURL => landing_page,
      :downloadURL => resource["url"],
      :format => resource["format"],
      :mediaType => resource["mimetype"] || resource["content_type"],
    }
    distribution[:issued] = Date.parse(resource["created"]) rescue nil
    distribution[:modified] = Date.parse(resource["last_modified"] || resource["revision_timestamp"]) rescue nil
    distribution[:byteSize] = Integer(resource["size"]) rescue nil
    distributions << Distribution.new(self, ckan_resource: distribution)
  end
  return distributions
rescue
  nil
end

#identifierObject

An identifier for the dataset

See Also:



85
86
87
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 85

def identifier
  .lookup("name") || @identifier
end

#issuedObject

Date the dataset was released

See Also:



185
186
187
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 185

def issued
  Date.parse .lookup("metadata_created") rescue nil
end

#keywordsObject

Keywords for the dataset

See Also:



101
102
103
104
105
106
107
108
109
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 101

def keywords
  keywords = []
  .lookup("tags").each do |tag|
    keywords << tag
  end
  return keywords
rescue
  []
end

#landing_pageObject

A web page which can be used to gain access to the dataset



92
93
94
95
96
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 92

def landing_page
  .lookup("extras", "landing_page") ||
  .lookup("url") ||
  .lookup("ckan_url")
end

#languageObject

The language of the dataset

See Also:



212
213
214
215
216
217
218
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 212

def language
  .lookup("language") ||
  .lookup("metadata_language") ||
  .lookup("extras", "metadata_language") ||
  .lookup("extras", "language", 0) ||
  .lookup("extras", "language")
end

#licensesObject

A list of licenses.

See Also:



137
138
139
140
141
142
143
144
145
146
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 137

def licenses
  id = .lookup("license_id")
  uri = .lookup("license_url") || .lookup("extras", "licence_url")
  name = .lookup("license_title") || .lookup("extras", "licence_url_title")
  if [id, uri, name].any?
    [License.new(:id => id, :uri => uri, :name => name)]
  else
    []
  end
end

#maintainersObject



126
127
128
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 126

def maintainers
  extract_agent('maintainer', 'maintainer_email')
end

#modifiedObject

Date the dataset was modified

See Also:



192
193
194
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 192

def modified
  Date.parse .lookup("metadata_modified") rescue nil
end

#publishersObject

A list of publishers.

See Also:



114
115
116
117
118
119
120
121
122
123
124
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 114

def publishers
  org = fetch_organization
  result = if org
    [org]
  elsif group_id = .lookup('groups', 0, 'id')
    [fetch_publisher(group_id)]
  else
    []
  end
  result.compact
end

#publishing_formatSymbol

The publishing format for the dataset.

Returns:

  • (Symbol)

    :ckan

See Also:



62
63
64
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 62

def publishing_format
  :ckan
end

#spatialObject

Spatial coverage of the dataset

See Also:



233
234
235
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 233

def spatial
  extract_spatial || extract_bbox
end

#temporalObject

The temporal coverage of the dataset

See Also:



199
200
201
202
203
204
205
206
207
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 199

def temporal
  from = .lookup("extras", "temporal_coverage-from") ||
         .lookup("extras", "temporal-extent-begin")
  to = .lookup("extras", "temporal_coverage-to") ||
       .lookup("extras", "temporal-extent-end")
  start_date = Date.parse from rescue nil
  end_date = Date.parse to rescue nil
  Temporal.new(:start => start_date, :end => end_date)
end

#themeObject

The main category of the dataset

See Also:



223
224
225
226
227
228
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 223

def theme
  .lookup("extras", "theme", 0) ||
  .lookup("extras", "theme-primary") ||
  .lookup("groups", 0, "name") ||
  .lookup("groups", 0)
end

#update_frequencyObject

How frequently the data is updated.



174
175
176
177
178
179
180
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 174

def update_frequency
  .lookup("extras", "update_frequency") ||
  .lookup("extras", "frequency-of-update") ||
  .lookup("extras", "accrual_periodicity")
rescue
  nil
end