Class: Nice::DataGouv::Dataset

Inherits:
Object
  • Object
show all
Defined in:
lib/nice/data_gouv/dataset.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Dataset

Returns a new instance of Dataset.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/nice/data_gouv/dataset.rb', line 9

def initialize(attributes = {})
  @id = attributes['id']
  @name = attributes['name']
  @title = attributes['title']
  @notes = attributes['notes']
  @created_at = attributes['metadata_created']
  @metadata_modified = attributes['metadata_modified']
  @tags = (attributes['tags'] || []).map { |t| t.is_a?(Hash) ? t['name'] : t }

  @organization = if attributes['organization']
                    Organization.new(attributes['organization'])
                  end

  @resources = (attributes['resources'] || []).map do |resource_data|
    Resource.new(resource_data)
  end
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



7
8
9
# File 'lib/nice/data_gouv/dataset.rb', line 7

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/nice/data_gouv/dataset.rb', line 7

def id
  @id
end

#metadata_modifiedObject (readonly)

Returns the value of attribute metadata_modified.



7
8
9
# File 'lib/nice/data_gouv/dataset.rb', line 7

def 
  @metadata_modified
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/nice/data_gouv/dataset.rb', line 7

def name
  @name
end

#notesObject (readonly)

Returns the value of attribute notes.



7
8
9
# File 'lib/nice/data_gouv/dataset.rb', line 7

def notes
  @notes
end

#organizationObject (readonly)

Returns the value of attribute organization.



7
8
9
# File 'lib/nice/data_gouv/dataset.rb', line 7

def organization
  @organization
end

#resourcesObject (readonly)

Returns the value of attribute resources.



7
8
9
# File 'lib/nice/data_gouv/dataset.rb', line 7

def resources
  @resources
end

#tagsObject (readonly)

Returns the value of attribute tags.



7
8
9
# File 'lib/nice/data_gouv/dataset.rb', line 7

def tags
  @tags
end

#titleObject (readonly)

Returns the value of attribute title.



7
8
9
# File 'lib/nice/data_gouv/dataset.rb', line 7

def title
  @title
end

Instance Method Details

#to_hObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/nice/data_gouv/dataset.rb', line 27

def to_h
  {
    'id' => @id,
    'name' => @name,
    'title' => @title,
    'notes' => @notes,
    'organization' => @organization&.to_h,
    'resources' => @resources.map(&:to_h),
    'tags' => @tags,
    'created_at' => @created_at,
    'metadata_modified' => @metadata_modified
  }
end