Class: Workarea::Search::HashText

Inherits:
Object
  • Object
show all
Defined in:
app/models/workarea/search/hash_text.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ HashText

Returns a new instance of HashText.



6
7
8
# File 'app/models/workarea/search/hash_text.rb', line 6

def initialize(hash)
  @hash = hash || {}
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



4
5
6
# File 'app/models/workarea/search/hash_text.rb', line 4

def hash
  @hash
end

Instance Method Details

#textString

Flatten out all values in the hash and returns a comma-delimited string. Used for entering catalog Hash data into the search index for full text searching.

Returns:



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/workarea/search/hash_text.rb', line 17

def text
  hash.map do |key, value|
    value_string = if value.is_a?(Hash)
                     HashText.new(value).text
                   elsif value.is_a?(Array)
                     value.join(', ')
                   else
                     value
                   end

    "#{key.to_s.humanize}: #{value_string}"
  end.join('; ')
end