Class: Krikri::ValidationReportList
- Inherits:
-
Object
- Object
- Krikri::ValidationReportList
- Defined in:
- lib/krikri/validation_report_list.rb
Overview
Constructs a list of Validation Reports
Constant Summary collapse
- REQUIRED_FIELDS =
['dataProvider_name', 'isShownAt_id', 'preview_id', 'sourceResource_rights', 'sourceResource_title', 'sourceResource_type_id']
Instance Attribute Summary collapse
-
#report_list ⇒ Object
readonly
Returns the value of attribute report_list.
Instance Method Summary collapse
-
#initialize ⇒ ValidationReportList
constructor
A new instance of ValidationReportList.
-
#list_for_display(solr_response) ⇒ Object
Transform Hash of key-value pairs into Array of Hashes.
-
#missing_field_totals ⇒ Object
Returns the number of items missing each required field.
-
#report_link(name, count) ⇒ Object
Construct a link and display label for a validation report The param ‘report_name’ in the constructed link is not used by Solr - it is for display purposes only @param: String, int @return: Hash.
Constructor Details
#initialize ⇒ ValidationReportList
Returns a new instance of ValidationReportList.
10 11 12 13 |
# File 'lib/krikri/validation_report_list.rb', line 10 def initialize @blacklight_config = Blacklight::Configuration.new @report_list = list_for_display(missing_field_totals) end |
Instance Attribute Details
#report_list ⇒ Object (readonly)
Returns the value of attribute report_list.
4 5 6 |
# File 'lib/krikri/validation_report_list.rb', line 4 def report_list @report_list end |
Instance Method Details
#list_for_display(solr_response) ⇒ Object
Transform Hash of key-value pairs into Array of Hashes.
example: { "field_name"=>[nil,2] } is tranformed into
[{ :label => "field_name (2)", :link_url => "validation_reports?[...]"}]
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/krikri/validation_report_list.rb', line 31 def list_for_display(solr_response) if solr_response && solr_response['facet_counts'] && fields = solr_response['facet_counts']['facet_fields'] return fields.each_with_object([]) do |(key, value), array| array << report_link(key, value[1]) end end nil end |
#missing_field_totals ⇒ Object
Returns the number of items missing each required field
18 19 20 21 22 23 24 25 26 |
# File 'lib/krikri/validation_report_list.rb', line 18 def missing_field_totals solr_params = { :rows => 0, 'facet.field' => REQUIRED_FIELDS, 'facet.mincount' => 10000000, 'facet.missing' => true } Blacklight::SolrRepository.new(@blacklight_config).search(solr_params) end |
#report_link(name, count) ⇒ Object
Construct a link and display label for a validation report The param ‘report_name’ in the constructed link is not used by Solr
- it is for display purposes only
@param: String, int @return: Hash
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/krikri/validation_report_list.rb', line 49 def report_link(name, count) link = { :label => "#{name} (#{count})" } if count > 0 link[:url] = "validation_reports?q=-#{name}:[*%20TO%20*]" \ "&report_name=#{name}" end link end |