Class: Clevic::TableSearcher

Inherits:
Object
  • Object
show all
Includes:
OrderedDataset
Defined in:
lib/clevic/table_searcher.rb

Overview

Search for a record in the collection given a set of criteria. One of the criteria will be a starting record, and the search method should return the matching record next after this.

Instance Attribute Summary collapse

Attributes included from OrderedDataset

#dataset

Instance Method Summary collapse

Methods included from OrderedDataset

#order_attributes

Constructor Details

#initialize(dataset, search_criteria, field) ⇒ TableSearcher

dataset is a Sequel::Dataset, which has an associated Sequel::Model field is an instance of Clevic::Field search_criteria responds to from_start?, direction, whole_words? and search_text



18
19
20
21
22
23
24
25
26
# File 'lib/clevic/table_searcher.rb', line 18

def initialize( dataset, search_criteria, field )
  raise "field must be specified" if field.nil?
  raise "unknown order #{search_criteria.direction}" unless [:forwards, :backwards].include?( search_criteria.direction )

  self.dataset = dataset

  @search_criteria = search_criteria
  @field = field
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



13
14
15
# File 'lib/clevic/table_searcher.rb', line 13

def field
  @field
end

#search_criteriaObject (readonly)

Returns the value of attribute search_criteria.



13
14
15
# File 'lib/clevic/table_searcher.rb', line 13

def search_criteria
  @search_criteria
end

Instance Method Details

#search(start_entity = nil) ⇒ Object

start_entity is the entity to start from, ie any record found after it will qualify return the first entity found that matches the criteria



30
31
32
# File 'lib/clevic/table_searcher.rb', line 30

def search( start_entity = nil )
  search_dataset( start_entity ).first
end