Class: MartSearch::DataView
- Inherits:
-
Object
- Object
- MartSearch::DataView
- Defined in:
- lib/martsearch/data_view.rb
Overview
DataView class for modelling a display of data.
Instance Attribute Summary (collapse)
-
- (Object) config
readonly
Returns the value of attribute config.
-
- (Object) javascript_base
Returns the value of attribute javascript_base.
-
- (Object) javascript_head
Returns the value of attribute javascript_head.
-
- (Object) stylesheet
Returns the value of attribute stylesheet.
Instance Method Summary (collapse)
-
- (Array) attribution_links(result_data)
Function to provide details for attribution links to the sources of the data.
-
- (Array) data_origin_links(result_data)
Function to provide details for the links to the actual data that makes up the data view.
-
- (String) description
The short description for this DataView.
-
- (Boolean) display
Whether to display this dataview or not.
-
- (Boolean) display_for_result?(result, errors)
Function that determines if we have enough data from the DataSets to be able to produce a display.
-
- (DataView) initialize(conf)
constructor
A new instance of DataView.
-
- (String) internal_name
The internal_name for this DataView.
-
- (String) name
The display name for this DataView.
-
- (Hash) search_errors(dataset_errors)
Function to determine if there are any search errors related to this dataview.
-
- (Boolean) use_custom_routes?
True/False.
-
- (Boolean) use_custom_view_helpers?
True/False.
Constructor Details
- (DataView) initialize(conf)
A new instance of DataView
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
- (Array) attribution_links(result_data)
Function to provide details for attribution links to the sources of the data.
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 |
- (Array) data_origin_links(result_data)
Function to provide details for the links to the actual data that makes up the data view.
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>"#{ds_name}"</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
The short description for this DataView
31 32 33 |
# File 'lib/martsearch/data_view.rb', line 31 def description @config[:description] end |
- (Boolean) display
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.
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
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
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.
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?
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?
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 |