Class: Quby::TableBackend::RangeTree
- Inherits:
-
Object
- Object
- Quby::TableBackend::RangeTree
- Defined in:
- lib/quby/table_backend/range_tree.rb
Class Method Summary collapse
-
.from_csv(levels:, compare:, data:) ⇒ Object
load csv data into a tree.
Instance Method Summary collapse
-
#initialize(levels:, tree:) ⇒ RangeTree
constructor
A new instance of RangeTree.
-
#lookup(parameters) ⇒ Object
Given a parameters hash that contains a value or range for every level in the tree, find and return the normscore.
Constructor Details
#initialize(levels:, tree:) ⇒ RangeTree
Returns a new instance of RangeTree.
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.
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 |