Class: Tem::Mr::Search::Db

Inherits:
Object
  • Object
show all
Defined in:
lib/tem_mr_search/db.rb

Overview

Mock database for the Map-Reduce proof of concept.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Db

Creates a new mock database.

Args:

path:: filesystem path to the YAML file containing the database


19
20
21
22
# File 'lib/tem_mr_search/db.rb', line 19

def initialize(path)
  @data = File.open(path, 'r') { |f| YAML.load f }
  @id_attribute = 'flight'
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



12
13
14
# File 'lib/tem_mr_search/db.rb', line 12

def data
  @data
end

#id_attributeObject (readonly)

Returns the value of attribute id_attribute.



13
14
15
# File 'lib/tem_mr_search/db.rb', line 13

def id_attribute
  @id_attribute
end

Instance Method Details

#item(item_index) ⇒ Object

Retrieves an item in table scan order.

Args:

item_index:: the item's 0-based index in table scan order

Returns a hash with the item data.



35
36
37
# File 'lib/tem_mr_search/db.rb', line 35

def item(item_index)
  @data[item_index]
end

#item_by_id(item_id) ⇒ Object

Retrieves an item using its primary key.

Args:

item_id:: the item's primary key

Returns a hash with the item data.



45
46
47
# File 'lib/tem_mr_search/db.rb', line 45

def item_by_id(item_id)
  @data.find { |item| item[@id_attribute] == item_id }
end

#lengthObject

The number of records in the database.



25
26
27
# File 'lib/tem_mr_search/db.rb', line 25

def length
  @data.length
end