Class: Workarea::Search::FacetSorting
- Inherits:
-
Object
- Object
- Workarea::Search::FacetSorting
- Defined in:
- app/queries/workarea/search/facet_sorting.rb,
app/queries/workarea/search/facet_sorting/size.rb
Defined Under Namespace
Classes: Size
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #apply(results, size = full_result_size) ⇒ Object
- #dynamic? ⇒ Boolean
- #dynamic_option ⇒ Object
-
#initialize(name) ⇒ FacetSorting
constructor
A new instance of FacetSorting.
- #option ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(name) ⇒ FacetSorting
Returns a new instance of FacetSorting.
6 7 8 |
# File 'app/queries/workarea/search/facet_sorting.rb', line 6 def initialize(name) @name = name.to_sym end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'app/queries/workarea/search/facet_sorting.rb', line 4 def name @name end |
Instance Method Details
#apply(results, size = full_result_size) ⇒ Object
17 18 19 20 |
# File 'app/queries/workarea/search/facet_sorting.rb', line 17 def apply(results, size = full_result_size) return results unless dynamic? Hash[dynamic_option.call(name, results).first(size)] end |
#dynamic? ⇒ Boolean
39 40 41 |
# File 'app/queries/workarea/search/facet_sorting.rb', line 39 def dynamic? dynamic_option.present? end |
#dynamic_option ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'app/queries/workarea/search/facet_sorting.rb', line 28 def dynamic_option @dynamic_option ||= if option.respond_to?(:call) option elsif option.try(:constantize).respond_to?(:call) option.constantize end rescue NameError @dynamic_option = nil end |
#option ⇒ Object
22 23 24 25 26 |
# File 'app/queries/workarea/search/facet_sorting.rb', line 22 def option @option ||= Workarea.config.search_facet_sorts[name].presence || default_option end |
#to_h ⇒ Object
10 11 12 13 14 15 |
# File 'app/queries/workarea/search/facet_sorting.rb', line 10 def to_h return dynamic_sorting if dynamic? return {} unless query_values[option].present? { order: query_values[option] } end |