Class: MartSearch::DataSource Abstract

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/martsearch/data_source.rb

Overview

This class is abstract.

Subclass and override #fetch_all_terms_for_indexing, #search to implement a custom DataSource class.

DataSource class for modelling a source for data.

Author:

Direct Known Subclasses

BiomartDataSource, DummyDataSource, FileSystemDataSource

Instance Method Summary (collapse)

Methods included from Utils

#build_http_client, #convert_array_to_hash

Constructor Details

- (DataSource) initialize(conf)

A new instance of DataSource

Parameters:

  • conf (Hash)

    configuration hash



16
17
18
19
# File 'lib/martsearch/data_source.rb', line 16

def initialize( conf )
  @conf = conf
  @url  = @conf[:url]
end

Instance Method Details

- (String) data_origin_url(query, conf)

This method is abstract.

Abstract method - Function to provide a link URL to the original datasource given a dataset query.

Parameters:

  • query (Array)

    An array of values to query the datasource for

  • conf (Hash)

    Configuration hash determining how to query the datasource

Returns:

  • (String)

    The URL to place in a link

Raises:



67
68
69
# File 'lib/martsearch/data_source.rb', line 67

def data_origin_url( query, conf )
  raise_error
end

- (Hash) fetch_all_terms_for_indexing(conf)

This method is abstract.

Abstract method - Function to query a datasource and return all of the data terms to be indexed.

Parameters:

  • conf (Hash)

    Configuration hash determining how to query the datasource

Returns:

  • (Hash)

    a hash containing the :headers (Array) and :data (Array of Arrays) to index - i.e. '{ :headers => [], :data => [[],[],[]] }'

Raises:



44
45
46
# File 'lib/martsearch/data_source.rb', line 44

def fetch_all_terms_for_indexing( conf )
  raise_error
end

- (Boolean) is_alive?

This method is abstract.

Abstract method - simple heartbeat function to check that the datasource is online.

Returns:

  • (Boolean)

    true/false depending on the state of the DataSource

Raises:



33
34
35
# File 'lib/martsearch/data_source.rb', line 33

def is_alive?
  raise_error
end

- (String) name

Helper function to return the 'internal_name' for this DataSource instance

Returns:

  • (String)

    The 'internal_name' for this DataSource instance



24
25
26
# File 'lib/martsearch/data_source.rb', line 24

def name
  @conf[:internal_name]
end

- (Array) search(query, conf)

This method is abstract.

Abstract method - Function to search a datasource given an appropriate configuration.

Parameters:

  • query (Array)

    An array of values to query the datasource for

  • conf (Hash)

    Configuration hash determining how to query the datasource

Returns:

  • (Array)

    An array of objects representing the data retrieved from the datasource

Raises:



55
56
57
# File 'lib/martsearch/data_source.rb', line 55

def search( query, conf )
  raise_error
end