Class: Blacklight::FieldRetriever

Inherits:
Object
  • Object
show all
Defined in:
app/services/blacklight/field_retriever.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document, field_config, view_context = nil) ⇒ FieldRetriever

Returns a new instance of FieldRetriever.

Parameters:



8
9
10
11
12
# File 'app/services/blacklight/field_retriever.rb', line 8

def initialize(document, field_config, view_context = nil)
  @document = document
  @field_config = field_config
  @view_context = view_context
end

Instance Attribute Details

#documentBlacklight::Document (readonly)



15
16
17
# File 'app/services/blacklight/field_retriever.rb', line 15

def document
  @document
end

#field_configBlacklight::Configuration::Field (readonly)



17
18
19
# File 'app/services/blacklight/field_retriever.rb', line 17

def field_config
  @field_config
end

#view_contextActionView::Base (readonly)

Returns:

  • (ActionView::Base)


19
20
21
# File 'app/services/blacklight/field_retriever.rb', line 19

def view_context
  @view_context
end

Instance Method Details

#fetchArray

Returns:

  • (Array)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/services/blacklight/field_retriever.rb', line 24

def fetch
  if field_config.highlight
    value = retrieve_highlight
  end
  if value.blank?
    value = if field_config.accessor
              retieve_using_accessor
            elsif field_config.values
              retrieve_values
            else
              retrieve_simple
            end
  end
  Array.wrap(value)
end