class Datasets::RdatasetsList
Constants
- Record
Public Class Methods
new()
click to toggle source
Calls superclass method
Datasets::Dataset::new
# File lib/datasets/rdatasets.rb, line 19 def initialize super @metadata.id = "rdatasets" @metadata.name = "Rdatasets" @metadata.url = "https://vincentarelbundock.github.io/Rdatasets/" @metadata.licenses = ["GPL-3"] @data_url = "https://raw.githubusercontent.com/vincentarelbundock/Rdatasets/master/datasets.csv" @data_path = cache_dir_path + "datasets.csv" end
Public Instance Methods
each(&block)
click to toggle source
# File lib/datasets/rdatasets.rb, line 46 def each(&block) filter(&block) end
filter(package: nil, dataset: nil) { |record(*fields)| ... }
click to toggle source
# File lib/datasets/rdatasets.rb, line 29 def filter(package: nil, dataset: nil) return to_enum(__method__, package: package, dataset: dataset) unless block_given? conds = {} conds["Package"] = package if package conds["Item"] = dataset if dataset if conds.empty? each_row {|row| yield Record.new(*row.fields) } else each_row do |row| if conds.all? {|k, v| row[k] == v } yield Record.new(*row.fields) end end end end
Private Instance Methods
each_row(&block)
click to toggle source
# File lib/datasets/rdatasets.rb, line 50 def each_row(&block) download(@data_path, @data_url) unless @data_path.exist? CSV.open(@data_path, headers: :first_row, converters: :all) do |csv| csv.each(&block) end end