Class: Udongo::Search::Term

Inherits:
Object
  • Object
show all
Defined in:
lib/udongo/search/term.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string, controller: nil) ⇒ Term

Returns a new instance of Term.



5
6
7
8
# File 'lib/udongo/search/term.rb', line 5

def initialize(string, controller: nil)
  @string = string
  @controller = controller
end

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



3
4
5
# File 'lib/udongo/search/term.rb', line 3

def controller
  @controller
end

#stringObject (readonly)

Returns the value of attribute string.



3
4
5
# File 'lib/udongo/search/term.rb', line 3

def string
  @string
end

Instance Method Details

#localeObject



10
11
12
13
# File 'lib/udongo/search/term.rb', line 10

def locale
  return controller.locale if controller.present?
  Udongo.config.i18n.app.default_locale.to_sym
end

#synonymObject



15
16
17
18
19
# File 'lib/udongo/search/term.rb', line 15

def synonym
  SearchSynonym.where(locale: locale)
    .where('concat(",", synonyms, ",") LIKE ?', "%,#{string},%")
    .take
end

#valid?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/udongo/search/term.rb', line 21

def valid?
  @string.present?
end

#valueObject



25
26
27
28
# File 'lib/udongo/search/term.rb', line 25

def value
  return synonym.term if synonym
  string
end