Class: Workarea::Search::HashText
- Inherits:
-
Object
- Object
- Workarea::Search::HashText
- Defined in:
- app/models/workarea/search/hash_text.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
Instance Method Summary collapse
-
#initialize(hash) ⇒ HashText
constructor
A new instance of HashText.
-
#text ⇒ String
Flatten out all values in the hash and returns a comma-delimited string.
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
#hash ⇒ Object (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
#text ⇒ String
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.
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 |