Module: DataKitten::PublishingFormats::CKAN

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

Instance Method Summary collapse

Instance Method Details

#base_uriObject



246
247
248
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 246

def base_uri
  DataKitten::PublishingFormats::CKAN.get_base(self.uri)
end

#contributorsObject



139
140
141
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 139

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

#data_titleObject

The human-readable title of the dataset.

See Also:



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

def data_title
  .lookup("title")
end

#descriptionObject

A brief description of the dataset



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

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

#distributionsObject

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



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 160

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:



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

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

#issuedObject

Date the dataset was released

See Also:



194
195
196
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 194

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

#keywordsObject

Keywords for the dataset

See Also:



110
111
112
113
114
115
116
117
118
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 110

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



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

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

#languageObject

The language of the dataset

See Also:



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

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:



146
147
148
149
150
151
152
153
154
155
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 146

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



135
136
137
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 135

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

#modifiedObject

Date the dataset was modified

See Also:



201
202
203
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 201

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

#publishersObject

A list of publishers.

See Also:



123
124
125
126
127
128
129
130
131
132
133
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 123

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:



71
72
73
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 71

def publishing_format
  :ckan
end

#spatialObject

Spatial coverage of the dataset

See Also:



242
243
244
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 242

def spatial
  extract_spatial || extract_bbox
end

#temporalObject

The temporal coverage of the dataset

See Also:



208
209
210
211
212
213
214
215
216
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 208

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:



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

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.



183
184
185
186
187
188
189
# File 'lib/data_kitten/publishing_formats/ckan.rb', line 183

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