Module: DataKitten::PublishingFormats::Datapackage

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

Overview

Datapackage metadata format module. Automatically mixed into Dataset for datasets that include a datapackage.json.

See Also:

Instance Method Summary collapse

Instance Method Details

#change_historyArray

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.

Returns:

  • (Array)

    An array of changes. Exact format depends on the source.

See Also:



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# 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

#contributorsObject

A list of contributors.



75
76
77
78
79
# 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

#data_titleObject

The human-readable title of the dataset.

See Also:



91
92
93
# File 'lib/data_kitten/publishing_formats/datapackage.rb', line 91

def data_title
  package.title || package.name
end

#descriptionObject

A brief description of the dataset



98
99
100
# File 'lib/data_kitten/publishing_formats/datapackage.rb', line 98

def description
  package.description
end

#distributionsObject

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



84
85
86
# File 'lib/data_kitten/publishing_formats/datapackage.rb', line 84

def distributions
  package.resources.map { |resource| Distribution.new(self, datapackage_resource: resource) }
end

#keywordsObject

Keywords for the dataset

See Also:



105
106
107
# File 'lib/data_kitten/publishing_formats/datapackage.rb', line 105

def keywords
  package.keywords
end

#licensesObject

A list of licenses.

See Also:



58
59
60
61
62
# 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

#maintainersObject

A list of maintainers.



40
41
42
43
44
# 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

#modifiedObject

Date the dataset was modified



119
120
121
# File 'lib/data_kitten/publishing_formats/datapackage.rb', line 119

def modified
  package.last_modified
end

#publishersObject

A list of publishers.

See Also:



49
50
51
52
53
# 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

#publishing_formatSymbol

The publishing format for the dataset.

Returns:

  • (Symbol)

    :datapackage

See Also:



33
34
35
# File 'lib/data_kitten/publishing_formats/datapackage.rb', line 33

def publishing_format
  :datapackage
end

#rightsObject



64
65
66
67
68
69
70
# 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

#sourcesObject

Where the data is sourced from

See Also:



112
113
114
115
116
# 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