Module: GeneralUtils

Included in:
CategoryFormat, DocsHelper, FacetsQuery, MultiDataset, ParamParser, QueryFormat
Defined in:
app/helpers/general_utils.rb

Instance Method Summary collapse

Instance Method Details

Generate link html



50
51
52
# File 'app/helpers/general_utils.rb', line 50

def genLink(name, path, em)
  return (em ? "<li><em>" : "<li>") + link_to(name, path) + (em ? "</li></em>" : "</li>")
end

#get_date_index(key) ⇒ Object

Gets the index and field name for date param



27
28
29
30
31
32
33
# File 'app/helpers/general_utils.rb', line 27

def get_date_index(key)
  key, index = key.split("_sindex_")
  dataspec = @dataspecs_index_name[index]
  fieldname = key.split("range_")[1]

  return fieldname, dataspec
end

#get_search_param(params) ⇒ Object

Gets the search param name only- minus sindex



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/helpers/general_utils.rb', line 12

def get_search_param(params)
  params.each do |key, value|
    # Find one that is search term
    if key.include?("_sindex_")
      key, index = key.split("_sindex_")

      # Get dataspec and item
      dataspec = @dataspecs_index_name[index]
      item = {key => value}
      return item, dataspec
    end
  end
end

#getHR(name, dataspec) ⇒ Object

Gets the human readable name of a field



3
4
5
6
7
8
9
# File 'app/helpers/general_utils.rb', line 3

def getHR(name, dataspec)
  dataspec.field_info.each do |i|
    if paramMatch?(i, name)
      return i["Human Readable Name"]
    end
  end
end

#paramMatch?(pl_item, compare) ⇒ Boolean

Checks params for form params of all types

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/helpers/general_utils.rb', line 36

def paramMatch?(pl_item, compare)
  form_params = pl_item["Form Params"]
  form_date_1 = pl_item["Form Params"][0]
  form_date_2 = pl_item["Form Params"][1]
  
  # Compare to both single item or array of params
  if compare.is_a? String
    return form_params == compare || form_date_1 == compare || form_date_2 == compare
  else
    return compare.keys.include?(form_params) || compare.keys.include?(form_date_1) || compare.keys.include?(form_date_2)
  end
end