Class: Datasets::Ggplot2Dataset
- Defined in:
- lib/datasets/ggplot2-dataset.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Dataset
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(ggplot2_dataset_name) ⇒ Ggplot2Dataset
constructor
A new instance of Ggplot2Dataset.
Methods inherited from Dataset
Constructor Details
#initialize(ggplot2_dataset_name) ⇒ Ggplot2Dataset
Returns a new instance of Ggplot2Dataset.
3 4 5 6 7 8 9 10 11 |
# File 'lib/datasets/ggplot2-dataset.rb', line 3 def initialize(ggplot2_dataset_name) super() @ggplot2_dataset_name = ggplot2_dataset_name @metadata.url = "https://ggplot2.tidyverse.org/reference/#{@ggplot2_dataset_name}.html" @metadata.description = lambda do fetch_description end end |
Instance Method Details
#each ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/datasets/ggplot2-dataset.rb', line 13 def each return to_enum(__method__) unless block_given? data_base_name = "#{@ggplot2_dataset_name}.csv" data_path = cache_dir_path + data_base_name data_url = "#{download_base_url}/data-raw/#{data_base_name}" download(data_path, data_url) CSV.open(data_path, headers: :first_row, converters: :all) do |csv| record_class = self.class::Record csv.each do |row| record = record_class.new(*row.fields) yield record end end end |