Class: Idhja22::Dataset::Datum
- Inherits:
-
Object
- Object
- Idhja22::Dataset::Datum
- Defined in:
- lib/idhja22/dataset/datum.rb,
lib/idhja22/dataset/errors.rb
Direct Known Subclasses
Defined Under Namespace
Classes: UnknownAttributeLabel, UnknownAttributeValue, UnknownCategoryLabel, UnknownCategoryValue
Instance Attribute Summary collapse
-
#attribute_labels ⇒ Object
Returns the value of attribute attribute_labels.
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#category_label ⇒ Object
Returns the value of attribute category_label.
Instance Method Summary collapse
- #[](attr_label) ⇒ Object
-
#initialize(row, attr_labels, category_label) ⇒ Datum
constructor
A new instance of Datum.
- #to_a ⇒ Object
Constructor Details
#initialize(row, attr_labels, category_label) ⇒ Datum
Returns a new instance of Datum.
6 7 8 9 10 11 |
# File 'lib/idhja22/dataset/datum.rb', line 6 def initialize(row, attr_labels, category_label) self.category_label = category_label raise NonUniqueAttributeLabels, "repeated attributes in #{attr_labels}" unless attr_labels == attr_labels.uniq self.attribute_labels = attr_labels self.attributes = row end |
Instance Attribute Details
#attribute_labels ⇒ Object
Returns the value of attribute attribute_labels.
4 5 6 |
# File 'lib/idhja22/dataset/datum.rb', line 4 def attribute_labels @attribute_labels end |
#attributes ⇒ Object
Returns the value of attribute attributes.
4 5 6 |
# File 'lib/idhja22/dataset/datum.rb', line 4 def attributes @attributes end |
#category_label ⇒ Object
Returns the value of attribute category_label.
4 5 6 |
# File 'lib/idhja22/dataset/datum.rb', line 4 def category_label @category_label end |
Instance Method Details
#[](attr_label) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/idhja22/dataset/datum.rb', line 17 def [](attr_label) if index = @attribute_labels.index(attr_label) self.attributes[index] else raise UnknownAttributeLabel, "unknown attribute label #{attr_label} in labels #{@attribute_labels.join(', ')}" end end |
#to_a ⇒ Object
13 14 15 |
# File 'lib/idhja22/dataset/datum.rb', line 13 def to_a attributes end |