Class: Datasets::SeabornData

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

Constant Summary collapse

URL_FORMAT =
"https://raw.githubusercontent.com/mwaskom/seaborn-data/master/%{name}.csv".freeze

Instance Attribute Summary

Attributes inherited from Dataset

#metadata

Instance Method Summary collapse

Methods inherited from Dataset

#clear_cache!, #to_table

Constructor Details

#initialize(name) ⇒ SeabornData

Returns a new instance of SeabornData.



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

def initialize(name)
  super()
  @metadata.id = "seaborn-data-#{name}"
  @metadata.name = "SeabornData: #{name}"
  @metadata.url = URL_FORMAT % {name: name}

  @data_path = cache_dir_path + (name + ".csv")
  @name = name
end

Instance Method Details

#each(&block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/datasets/seaborn-data.rb', line 15

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

  download(@data_path, @metadata.url) unless @data_path.exist?
  CSV.open(@data_path, headers: :first_row, converters: :all) do |csv|
    csv.each do |row|
      record = prepare_record(row)
      yield record
    end
  end
end