Class: ObjectSimilarity::FieldScorer

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

Direct Known Subclasses

ExactFieldScorer, NearnessFieldScorer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field, object, weight, options = {}) ⇒ FieldScorer

Returns a new instance of FieldScorer.



10
11
12
13
14
15
# File 'lib/object_similarity.rb', line 10

def initialize(field, object, weight, options = {})
  @field = field
  @object = object
  @weight = weight || 1
  @options = options
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



8
9
10
# File 'lib/object_similarity.rb', line 8

def field
  @field
end

#weightObject (readonly)

Returns the value of attribute weight.



8
9
10
# File 'lib/object_similarity.rb', line 8

def weight
  @weight
end

Instance Method Details

#get_value(object) ⇒ Object



27
28
29
30
31
# File 'lib/object_similarity.rb', line 27

def get_value(object)
  object.send(@field).tap do |v|
    raise SkipException if skip_value?(v)
  end
end

#skip_value?(value) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/object_similarity.rb', line 34

def skip_value?(value)
  false
end

#valueObject



21
22
23
24
25
# File 'lib/object_similarity.rb', line 21

def value
  @value ||= (@options[:value] || get_value(@object)).tap do |v|
    raise SkipException if skip_value?(v)
  end
end

#weighted_distance(other_object) ⇒ Object



17
18
19
# File 'lib/object_similarity.rb', line 17

def weighted_distance(other_object)
  distance(other_object) * @weight
end