Class: MartSearch::DataView

Inherits:
Object
  • Object
show all
Defined in:
lib/martsearch/data_view.rb

Overview

DataView class for modelling a display of data.

Author:

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (DataView) initialize(conf)

Returns a new instance of DataView

Parameters:

  • conf (Hash)

    Configuration hash



14
15
16
17
18
# File 'lib/martsearch/data_view.rb', line 14

def initialize(conf)
  @config = conf
  @alredy_checked_datasets_ok = false
  check_conf_attrs
end

Instance Attribute Details

- (Object) config (readonly)

Returns the value of attribute config



10
11
12
# File 'lib/martsearch/data_view.rb', line 10

def config
  @config
end

- (Object) javascript_base

Returns the value of attribute javascript_base



11
12
13
# File 'lib/martsearch/data_view.rb', line 11

def javascript_base
  @javascript_base
end

- (Object) javascript_head

Returns the value of attribute javascript_head



11
12
13
# File 'lib/martsearch/data_view.rb', line 11

def javascript_head
  @javascript_head
end

- (Object) stylesheet

Returns the value of attribute stylesheet



11
12
13
# File 'lib/martsearch/data_view.rb', line 11

def stylesheet
  @stylesheet
end

Instance Method Details

Function to provide details for attribution links to the sources of the data.

Parameters:

  • result_data (Hash)

    The result_data stash of returned data for a given gene/doc

Returns:

  • (Array)

    An array of arrays containing the [ link_text, link_url ]



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/martsearch/data_view.rb', line 94

def attribution_links( result_data )
  MartSearch::Controller.instance().logger.debug("[MartSearch::DataView] '#{self.internal_name}' ::attribution_links - running attribution_links()")
  martsearch = MartSearch::Controller.instance()
  datasets   = martsearch.datasets
  links      = []
  
  [ :required, :optional ].each do |ds_class|
    @config[:datasets][ds_class].each do |ds_name|
      if result_data.has_key?(ds_name.to_sym) and result_data[ds_name.to_sym] != nil
        dataset = datasets[ds_name.to_sym]
        unless dataset.config[:attribution].nil? and dataset.config[:attribution_link].nil?
          links.push( [ dataset.config[:attribution], dataset.config[:attribution_link] ] )
        end
      end
    end
  end
  
  MartSearch::Controller.instance().logger.debug("[MartSearch::DataView] '#{self.internal_name}' ::attribution_links - running attribution_links() - DONE")
  return links.uniq
end

Function to provide details for the links to the actual data that makes up the data view.

Parameters:

  • result_data (Hash)

    The result_data stash of returned data for a given gene/doc

Returns:

  • (Array)

    An array of arrays containing the [ link_text, link_url ]



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/martsearch/data_view.rb', line 120

def data_origin_links( result_data )
  MartSearch::Controller.instance().logger.debug("[MartSearch::DataView] '#{self.internal_name}' ::data_origin_links - running data_origin_links()")
  martsearch = MartSearch::Controller.instance()
  datasets   = martsearch.datasets
  links      = []
  
  [ :required, :optional ].each do |ds_class|
    @config[:datasets][ds_class].each do |ds_name|
      if result_data.has_key?(ds_name.to_sym) and result_data[ds_name.to_sym] != nil
        dataset = datasets[ds_name.to_sym]
        
        links.push([
          "#{dataset.config[:attribution]} - <em>&quot;#{ds_name}&quot;</em>",
          dataset.data_origin_url( result_data[:index][ dataset.joined_index_field.to_sym ] )
        ])
      end
    end
  end
  
  MartSearch::Controller.instance().logger.debug("[MartSearch::DataView] '#{self.internal_name}' ::data_origin_links - running data_origin_links() - DONE")
  return links.uniq
end

- (String) description

Returns The short description for this DataView

Returns:

  • (String)

    The short description for this DataView



31
32
33
# File 'lib/martsearch/data_view.rb', line 31

def description
  @config[:description]
end

- (Boolean) display

Returns Whether to display this dataview or not

Returns:

  • (Boolean)

    Whether to display this dataview or not



36
37
38
# File 'lib/martsearch/data_view.rb', line 36

def display
  @config[:display]
end

- (Boolean) display_for_result?(result, errors)

Function that determines if we have enough data from the DataSets to be able to produce a display.

Parameters:

  • result (Hash)

    One of the result objects from Controller#search

  • errors (Hash)

    A hash containing error records for the dataset searches (if any)

Returns:

  • (Boolean)

    True/False



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/martsearch/data_view.rb', line 56

def display_for_result?( result, errors )
  MartSearch::Controller.instance().logger.debug("[MartSearch::DataView] '#{self.internal_name}' ::search - running display_for_result?()")
  check_datasets unless @alredy_checked_datasets_ok
  display = false
  
  if self.display
    @config[:datasets][:required].each do |ds_name|
      display = true unless result[ds_name.to_sym].nil?
      display = true unless errors[ds_name.to_sym].nil?
    end
  end
  
  return display
end

- (String) internal_name

Returns The internal_name for this DataView

Returns:

  • (String)

    The internal_name for this DataView



26
27
28
# File 'lib/martsearch/data_view.rb', line 26

def internal_name
  @config[:internal_name]
end

- (String) name

Returns The display name for this DataView

Returns:

  • (String)

    The display name for this DataView



21
22
23
# File 'lib/martsearch/data_view.rb', line 21

def name
  @config[:name]
end

- (Hash) search_errors(dataset_errors)

Function to determine if there are any search errors related to this dataview.

Parameters:

  • dataset_errors (Hash)

    A hash of recorded search errors - keyed by dataset name

Returns:

  • (Hash)

    A hash of any dataset errors related to this view



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/martsearch/data_view.rb', line 75

def search_errors( dataset_errors )
  MartSearch::Controller.instance().logger.debug("[MartSearch::DataView] '#{self.internal_name}' ::search_errors - running search_errors()")
  errors = { :required => [], :optional => [] }
  
  [ :required, :optional ].each do |ds_class|
    @config[:datasets][ds_class].each do |ds_name|
      if dataset_errors.has_key?(ds_name.to_sym)
        errors[ds_class].push( dataset_errors[ds_name.to_sym] )
      end
    end
  end
  
  return errors
end

- (Boolean) use_custom_routes?

Returns True/False

Returns:

  • (Boolean)

    True/False



46
47
48
# File 'lib/martsearch/data_view.rb', line 46

def use_custom_routes?
  @config[:custom_routes] ? true : false
end

- (Boolean) use_custom_view_helpers?

Returns True/False

Returns:

  • (Boolean)

    True/False



41
42
43
# File 'lib/martsearch/data_view.rb', line 41

def use_custom_view_helpers?
  @config[:custom_view_helpers] ? true : false
end