Module: DataspecUtils

Included in:
ApplicationController, DocsHelper, FacetsQuery, SearchQuery
Defined in:
app/helpers/dataspec_utils.rb

Instance Method Summary collapse

Instance Method Details

#checkIfX(field, list) ⇒ Object

Takes a field and list to check it against



15
16
17
18
19
20
21
# File 'app/helpers/dataspec_utils.rb', line 15

def checkIfX(field, list)
  if list == nil
    return false
  else
    return list.include?(field["Field Name"]) ? true : false
  end
end

#getFieldDetails(name, field_details) ⇒ Object

Takes name and gets field details



3
4
5
6
7
8
9
10
11
12
# File 'app/helpers/dataspec_utils.rb', line 3

def getFieldDetails(name, field_details)
  field_details.each do |i|
    if name == i["Field Name"]
      return i
    end
  end

  # No matching field- this is an error with the dataspec
  return nil
end

#sortFields(field_list, field_details) ⇒ Object

Sorts lists of fields



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/helpers/dataspec_utils.rb', line 24

def sortFields(field_list, field_details)
  filtered_fields = Hash.new

  # Go through each field in field list and find in field_info json                                                                  
  field_list.each do |field|
    field_details.each do |field_info|
      # Save field name and location                                                                                                 
      filtered_fields[field] = field_info["Location"].to_i if field_info["Field Name"] == field.to_s
    end
  end

  # Sort by values and then return list of just keys                                                                                
  return filtered_fields.sort_by{|k, v| v}.collect{|i| i[0]}
end