class Datasets::Wine

Constants

Record

Public Class Methods

new() click to toggle source
Calls superclass method Datasets::Dataset::new
# File lib/datasets/wine.rb, line 22
def initialize
  super
  @metadata.id = 'wine'
  @metadata.name = 'Wine'
  @metadata.url = 'http://archive.ics.uci.edu/ml/datasets/wine'
  @metadata.description = -> { read_names }
end

Public Instance Methods

each() { |record| ... } click to toggle source
# File lib/datasets/wine.rb, line 30
def each
  return to_enum(__method__) unless block_given?

  open_data do |csv|
    csv.each do |row|
      next if row[0].nil?
      record = Record.new(*row)
      yield(record)
    end
  end
end

Private Instance Methods

open_data() { |csv| ... } click to toggle source
# File lib/datasets/wine.rb, line 53
def open_data
  data_path = cache_dir_path + 'wine.data'
  unless data_path.exist?
    data_url = 'http://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data'
    download(data_path, data_url)
  end
  CSV.open(data_path, converters: %i[numeric]) do |csv|
    yield(csv)
  end
end
read_names() click to toggle source
# File lib/datasets/wine.rb, line 44
def read_names
  names_path = cache_dir_path + 'wine.names'
  unless names_path.exist?
    names_url = 'http://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.names'
    download(names_path, names_url)
  end
  names_path.read
end