Class: Emendate::Examples::Csv

Inherits:
Object
  • Object
show all
Defined in:
lib/emendate/examples/csv.rb

Overview

Parses examples CSV and converts each row of that table to an Examples::Row

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCsv

Returns a new instance of Csv.



19
20
21
22
23
24
25
# File 'lib/emendate/examples/csv.rb', line 19

def initialize
  @rows = CSV.parse(File.read(Emendate.examples.file_path.call),
    headers: true)
    .map do |row|
    Row.new(row)
  end
end

Instance Attribute Details

#rowsObject (readonly)

Returns the value of attribute rows.



18
19
20
# File 'lib/emendate/examples/csv.rb', line 18

def rows
  @rows
end

Class Method Details

.rows(str, opt) ⇒ Object

even more convenient access to specific rows for testing



13
14
15
# File 'lib/emendate/examples/csv.rb', line 13

def rows(str, opt)
  new.retrieve_rows(str, opt)
end

Instance Method Details

#retrieve_rows(str, opt) ⇒ Object

Convenience method to extract specific row(s) by test fingerprint (test_string + test_options) for testing



29
30
31
32
# File 'lib/emendate/examples/csv.rb', line 29

def retrieve_rows(str, opt)
  rows.select { |row| row.test_string == str }
    .select { |row| row.test_options == opt }
end

#to_sObject Also known as: inspect



34
35
36
# File 'lib/emendate/examples/csv.rb', line 34

def to_s
  "#{rows.length} rows"
end