Class: Basset::Feature

Inherits:
Object
  • Object
show all
Defined in:
lib/basset/feature.rb

Overview

A class to hold a feature which consists of a name and a value. In the basic sense of document classification the name would be the word and the value would be the number of times that word appeared in the document.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value = 0) ⇒ Feature

Returns a new instance of Feature.



9
10
11
12
# File 'lib/basset/feature.rb', line 9

def initialize(name, value = 0)
  @name   = name
  @value  = value
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/basset/feature.rb', line 7

def name
  @name
end

#valueObject

Returns the value of attribute value.



7
8
9
# File 'lib/basset/feature.rb', line 7

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Object



14
15
16
17
18
# File 'lib/basset/feature.rb', line 14

def <=>(other)
  ret = self.name <=> other.name
  ret = self.value <=> other.value if ret.zero?
  ret
end

#==(other) ⇒ Object



20
21
22
23
24
# File 'lib/basset/feature.rb', line 20

def ==(other)
  ret = self.name == other.name
  ret = self.value == other.value if ret
  ret
end