Class: DataGov::Dataset
- Inherits:
-
Object
- Object
- DataGov::Dataset
- Defined in:
- lib/data_gov/dataset.rb
Instance Attribute Summary collapse
-
#ckan_metadata ⇒ Object
Returns the value of attribute ckan_metadata.
-
#id ⇒ Object
Returns the value of attribute id.
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
Class Method Summary collapse
Instance Method Summary collapse
- #download_resources ⇒ Object
-
#initialize(ckan_metadata) ⇒ Dataset
constructor
A new instance of Dataset.
- #pairtree ⇒ Object
- #pairtree_location ⇒ Object
- #save_ckan_metadata ⇒ Object
Constructor Details
#initialize(ckan_metadata) ⇒ Dataset
Returns a new instance of Dataset.
9 10 11 12 |
# File 'lib/data_gov/dataset.rb', line 9 def initialize() @ckan_metadata = @id = ['id'] end |
Instance Attribute Details
#ckan_metadata ⇒ Object
Returns the value of attribute ckan_metadata.
6 7 8 |
# File 'lib/data_gov/dataset.rb', line 6 def @ckan_metadata end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/data_gov/dataset.rb', line 6 def id @id end |
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
7 8 9 |
# File 'lib/data_gov/dataset.rb', line 7 def resources @resources end |
Class Method Details
.from_id(id) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/data_gov/dataset.rb', line 40 def self.from_id(id) instance = new('') instance.id = id instance. = JSON.parse(instance.pairtree.read('ckan.json')) instance end |
Instance Method Details
#download_resources ⇒ Object
26 27 28 29 |
# File 'lib/data_gov/dataset.rb', line 26 def download_resources puts "Downloading resources for #{id}" resources.map { |resource| resource.download } end |
#pairtree ⇒ Object
31 32 33 34 |
# File 'lib/data_gov/dataset.rb', line 31 def pairtree @pairtree ||= Pairtree.at(pairtree_location, create: true) .mk(id.delete('-')) end |
#pairtree_location ⇒ Object
36 37 38 |
# File 'lib/data_gov/dataset.rb', line 36 def pairtree_location ENV.fetch('DATA_DIR') end |
#save_ckan_metadata ⇒ Object
14 15 16 17 18 |
# File 'lib/data_gov/dataset.rb', line 14 def pairtree.open('ckan.json', 'w') do |io| io.write(JSON.pretty_generate()) end end |