Class: Documentrix::Documents::Cache::Records::Record

Inherits:
JSON::GenericObject
  • Object
show all
Defined in:
lib/documentrix/documents/cache/records.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Record

The initialize method sets default values for the text and norm attributes.

Parameters:

  • options (Hash) (defaults to: {})

    A hash containing optional parameters.



7
8
9
10
11
# File 'lib/documentrix/documents/cache/records.rb', line 7

def initialize(options = {})
  super
  self.text ||= ''
  self.norm ||= 0.0
end

Instance Method Details

#==(other) ⇒ FalseClass, TrueClass

The == method compares this record with another one by comparing their text fields.

Parameters:

Returns:

  • (FalseClass, TrueClass)

    true if both records have the same text, false otherwise.



38
39
40
# File 'lib/documentrix/documents/cache/records.rb', line 38

def ==(other)
  text == other.text
end

#tags_setDocumentrix::Utils::Tags

The tags_set method creates a new Documentrix::Utils::Tags object from the tags and source of this instance.

Returns:



27
28
29
# File 'lib/documentrix/documents/cache/records.rb', line 27

def tags_set
  Documentrix::Utils::Tags.new(tags, source:)
end

#to_sString Also known as: inspect

The to_s method returns a string representation of the object.

along with its similarity score.

Returns:

  • (String)

    A string containing the text and tags of the record,



17
18
19
20
21
# File 'lib/documentrix/documents/cache/records.rb', line 17

def to_s
  my_tags = tags_set
  my_tags.empty? or my_tags = " #{my_tags}"
  "#<#{self.class} #{text.inspect}#{my_tags} #{similarity || 'n/a'}>"
end