Module: Solis::QueryFilter

Included in:
Query
Defined in:
lib/solis/query/filter.rb

Instance Method Summary collapse

Instance Method Details

#filter(params) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/solis/query/filter.rb', line 3

def filter(params)
  if params.key?(:language)
    @language = params[:language].nil? || params[:language].blank? ? nil : params[:language]
  end

  parsed_filters = {values: ["VALUES ?type {#{target_class}}"], concepts: ['?concept a ?type .'] }
  if params.key?(:filters)
    filters = params[:filters]

    if filters.is_a?(String)
      parsed_filters[:concepts] << concept_by_string(filters)
    else
      i=0
      filters.each do |key, value|
        if is_key_a_shacl_entity?(key) #nodeKind sh:URI
          parsed_filters[:values] << values_for(key, value)
          parsed_filters[:concepts] << concepts_for(key)
        else
          parsed_filters[:concepts] << other_stuff(key, value, i)
        end
        i+=1
      end
    end
  end

  @filter = parsed_filters
  self
rescue StandardError => e
  LOGGER.error(e.message)
  LOGGER.error(e.backtrace.join("\n"))
  raise Error::GeneralError, e.message
end