module DataKitten::PublishingFormats::Datapackage
Datapackage
metadata format module. Automatically mixed into {Dataset} for datasets that include a datapackage.json
.
@see Dataset
Private Class Methods
# File lib/data_kitten/publishing_formats/datapackage.rb, line 13 def self.supported?(instance) begin if instance.send(:origin) == :git metadata = instance.send(:load_file, "datapackage.json") datapackage = DataPackage::Package.new( JSON.parse( metadata ) ) return datapackage.datapackage_version != nil else datapackage = DataPackage::Package.new( instance.url ) return datapackage.datapackage_version != nil end rescue => e false end end
Public Instance Methods
A history of changes to the Dataset
.
If {Dataset#source} is :git
, this is the git changelog for the actual distribution files, rather then the full unfiltered log.
@return [Array] An array of changes. Exact format depends on the source.
# File lib/data_kitten/publishing_formats/datapackage.rb, line 131 def change_history @change_history ||= begin if origin == :git # Get a log for each file in the local repo logs = distributions.map do |file| if file.path log = repository.log.path(file.path) # Convert to list of commits log.map{|commit| commit} else [] end end # combine all logs, make unique, and re-sort in date order logs.flatten.uniq.sort_by{|x| x.committer.date}.reverse else [] end end end
A list of contributors.
@see Dataset#contributors
# File lib/data_kitten/publishing_formats/datapackage.rb, line 75 def contributors package.contributors.map do |x| Agent.new(:name => x['name'], :uri => x['web'], :email => x['email']) end end
The human-readable title of the dataset.
@see Dataset#data_title
# File lib/data_kitten/publishing_formats/datapackage.rb, line 91 def data_title package.title || package.name end
A brief description of the dataset
@see Dataset#description
# File lib/data_kitten/publishing_formats/datapackage.rb, line 98 def description package.description end
A list of distributions, referred to as resources
by Datapackage
.
# File lib/data_kitten/publishing_formats/datapackage.rb, line 84 def distributions package.resources.map { |resource| Distribution.new(self, datapackage_resource: resource) } end
Keywords for the dataset
@see Dataset#keywords
# File lib/data_kitten/publishing_formats/datapackage.rb, line 105 def keywords package.keywords end
A list of licenses.
@see Dataset#licenses
# File lib/data_kitten/publishing_formats/datapackage.rb, line 58 def licenses package.licenses.map do |x| License.new(:id => x['id'], :uri => x['url'], :name => x['name']) end end
A list of maintainers.
@see Dataset#maintainers
# File lib/data_kitten/publishing_formats/datapackage.rb, line 40 def maintainers package.maintainers.map do |x| Agent.new(:name => x['name'], :uri => x['web'], :email => x['email']) end end
Date the dataset was modified
# File lib/data_kitten/publishing_formats/datapackage.rb, line 119 def modified package.last_modified end
A list of publishers.
@see Dataset#publishers
# File lib/data_kitten/publishing_formats/datapackage.rb, line 49 def publishers package.publisher.map do |x| Agent.new(:name => x['name'], :uri => x['web'], :email => x['email']) end end
The publishing format for the dataset. @return [Symbol] :datapackage
@see Dataset#publishing_format
# File lib/data_kitten/publishing_formats/datapackage.rb, line 33 def publishing_format :datapackage end
# File lib/data_kitten/publishing_formats/datapackage.rb, line 64 def rights if package.property("rights") Rights.new( ( package.property("rights", [])).each_with_object({}){|(k,v), h| h[k.to_sym] = v} ) else nil end end
Where the data is sourced from
@see Dataset#sources
# File lib/data_kitten/publishing_formats/datapackage.rb, line 112 def sources package.sources.map do |x| Source.new(:label => x['name'], :resource => x['web']) end end
Private Instance Methods
# File lib/data_kitten/publishing_formats/datapackage.rb, line 154 def package if !@datapackage if origin == :git metadata = load_file("datapackage.json") @datapackage = DataPackage::Package.new( JSON.parse( metadata ) ) else @datapackage = DataPackage::Package.new( url ) end end @datapackage end