Class: Idhja22::Dataset::Datum

Inherits:
Object
  • Object
show all
Defined in:
lib/idhja22/dataset/datum.rb,
lib/idhja22/dataset/errors.rb

Direct Known Subclasses

Example

Defined Under Namespace

Classes: UnknownAttributeLabel, UnknownAttributeValue, UnknownCategoryLabel, UnknownCategoryValue

Instance Attribute Summary collapse

Instance Method Summary collapse

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_labelsObject

Returns the value of attribute attribute_labels.



4
5
6
# File 'lib/idhja22/dataset/datum.rb', line 4

def attribute_labels
  @attribute_labels
end

#attributesObject

Returns the value of attribute attributes.



4
5
6
# File 'lib/idhja22/dataset/datum.rb', line 4

def attributes
  @attributes
end

#category_labelObject

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_aObject



13
14
15
# File 'lib/idhja22/dataset/datum.rb', line 13

def to_a
  attributes
end