Class: Remi::DataSource

Inherits:
DataSubject show all
Includes:
Testing::DataStub
Defined in:
lib/remi/data_subject.rb,
lib/remi/cucumber.rb

Overview

The DataSource is a DataSubject meant to extract data from an external source and convert (parse) it into a dataframe.

Examples:


my_data_source = DataSource.new do
  extractor some_extractor
  parser some_parser
end

my_data_source.df #=> Returns a dataframe that is created by extracting data
                  #   from some_extractor and parsing it using some_parser.

Instance Attribute Summary

Attributes inherited from DataSubject

#context, #name

Instance Method Summary collapse

Methods included from Testing::DataStub

#empty_stub_df, #stub_boolean, #stub_date, #stub_datetime, #stub_decimal, #stub_df, #stub_float, #stub_integer, #stub_json, #stub_row_array, #stub_string, #stub_values

Methods inherited from DataSubject

#df=, #df_type, #dsl_eval, #dsl_eval!, #enforce_types, #field_symbolizer, #fields, #fields=

Constructor Details

#initialize(*args, **kargs, &block) ⇒ DataSource



153
154
155
156
157
# File 'lib/remi/data_subject.rb', line 153

def initialize(*args, **kargs, &block)
  @parser = Parser::None.new
  @parser.context = self
  super
end

Instance Method Details

#dfRemi::DataFrame

The dataframe will only be extracted and parsed once, and only if it has not already been set (e.g., using #df=).



195
196
197
# File 'lib/remi/data_subject.rb', line 195

def df
  @dataframe ||= parsed_as_dataframe
end

#extractArray<Object>



210
211
212
# File 'lib/remi/data_subject.rb', line 210

def extract
  @extract ||= extract!
end

#extract!Array

Extracts data from all of the extractors.



181
182
183
# File 'lib/remi/data_subject.rb', line 181

def extract!
  extractors.map { |e| e.extract }
end

#extractor(obj) ⇒ Array



166
167
168
# File 'lib/remi/data_subject.rb', line 166

def extractor(obj)
  extractors << obj unless extractors.include? obj
end

#extractorsArray



160
161
162
# File 'lib/remi/data_subject.rb', line 160

def extractors
  @extractors ||= []
end

#parseRemi::DataFrame

Converts all of the extracted data to a dataframe



187
188
189
# File 'lib/remi/data_subject.rb', line 187

def parse
  parser.parse *extract
end

#parser(obj = nil) ⇒ Object



172
173
174
175
176
177
# File 'lib/remi/data_subject.rb', line 172

def parser(obj = nil)
  return @parser unless obj
  obj.context = self

  @parser = obj
end

#resetRemi::DataFrame

This clears any previously extracted and parsed results. A subsequent call to #df will redo the extract and parse.



203
204
205
206
207
# File 'lib/remi/data_subject.rb', line 203

def reset
  @block = nil
  @dataframe = nil
  @extract = nil
end