Class: Quby::TableBackend::RangeTree

Inherits:
Object
  • Object
show all
Defined in:
lib/quby/table_backend/range_tree.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(levels:, tree:) ⇒ RangeTree

Returns a new instance of RangeTree.

Parameters:

  • tree (Hash<>)

    hash of hashes leading from parameter values/ranges to a result.



34
35
36
37
# File 'lib/quby/table_backend/range_tree.rb', line 34

def initialize(levels:, tree:)
  @levels = levels
  @tree = tree
end

Class Method Details

.from_csv(levels:, compare:, data:) ⇒ Object

load csv data into a tree. each row is a path through the tree. String and float types are used to make an exact match. A range is always a range between two floats where the range is between the low value (inclusive) and the high value (exclusive), written as 4:5 (low:high). These boundaries can be given as floats or integers, but internally they are always treated as a floats. The low and high values of a range cannot be equal. Use minfinity or infinity to create infinite ranges.

Parameters:

  • compare (Array<String>)

    An array of lookup types (string, float or range) for each column

  • data (Array<Array<>>)

    The rows describing a path through the tree.



52
53
54
55
56
57
# File 'lib/quby/table_backend/range_tree.rb', line 52

def self.from_csv(levels:, compare:, data:)
  tree = data.each_with_object({}) do |row, tree|
    add_to_tree(tree, row, levels, compare)
  end
  new(levels: levels, tree: tree)
end

Instance Method Details

#lookup(parameters) ⇒ Object

Given a parameters hash that contains a value or range for every level in the tree, find and return the normscore. ie. ‘lookup(10, raw: 5, scale: ’Inhibitie’, gender: ‘male’)‘ => 39



63
64
65
66
# File 'lib/quby/table_backend/range_tree.rb', line 63

def lookup(parameters)
  validate_parameters(parameters)
  lookup_score(parameters)
end