Class: Datasets::SeabornList

Inherits:
Dataset
  • Object
show all
Defined in:
lib/datasets/seaborn.rb

Instance Attribute Summary

Attributes inherited from Dataset

#metadata

Instance Method Summary collapse

Methods inherited from Dataset

#clear_cache!, #to_table

Constructor Details

#initializeSeabornList

Returns a new instance of SeabornList.



5
6
7
8
9
10
11
12
13
# File 'lib/datasets/seaborn.rb', line 5

def initialize
  super
  @metadata.id = "seaborn-data-list"
  @metadata.name = "seaborn: data list"
  @metadata.url = "https://github.com/mwaskom/seaborn-data"
  # Treat as the same license as seaborn
  @metadata.licenses = ["BSD-3-Clause"]
  @metadata.description = "Datasets for seaborn examples."
end

Instance Method Details

#each(&block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/datasets/seaborn.rb', line 15

def each(&block)
  return to_enum(__method__) unless block_given?

  data_path = cache_dir_path + "trees.json"
  url = "https://api.github.com/repos/mwaskom/seaborn-data/git/trees/master"
  download(data_path, url)

  tree = JSON.parse(File.read(data_path))["tree"]
  tree.each do |content|
    path = content["path"]
    next unless path.end_with?(".csv")
    dataset = File.basename(path, ".csv")
    record = {dataset: dataset}
    yield record
  end
end