Class: Krikri::FieldValueReport
- Inherits:
-
ActiveModelBase
- Object
- ActiveModelBase
- Krikri::FieldValueReport
- Defined in:
- app/models/krikri/field_value_report.rb
Overview
FieldValueReport gives all unique values for a given field within a document. It represents data that has been indexed into Solr.
This is a read-only object. FieldValueReports are not persisted.
Instance Attribute Summary collapse
-
#:field(: field) ⇒ Object
readonly
the name of the field.
- #:provider(: provider) ⇒ Object readonly
-
#field ⇒ Object
Returns the value of attribute field.
-
#provider ⇒ Object
Returns the value of attribute provider.
Class Method Summary collapse
-
.fields ⇒ Object
All of the fields for which a report can be created.
-
.find(field, provider_id) ⇒ Krikri::FieldValueReport
These two params act as a compound key.
Instance Method Summary collapse
- #enumerate_rows(opts = {}) ⇒ Object
-
#headers ⇒ Object
The headers for the report table, and the values to be returned from a Solr query.
Methods inherited from ActiveModelBase
Constructor Details
This class inherits a constructor from Krikri::ActiveModelBase
Instance Attribute Details
#:field(: field) ⇒ Object (readonly)
the name of the field. @example: ‘sourceResource_title’
13 |
# File 'app/models/krikri/field_value_report.rb', line 13 attr_accessor :field, :provider |
#:provider(: provider) ⇒ Object (readonly)
13 |
# File 'app/models/krikri/field_value_report.rb', line 13 attr_accessor :field, :provider |
#field ⇒ Object
Returns the value of attribute field.
13 14 15 |
# File 'app/models/krikri/field_value_report.rb', line 13 def field @field end |
#provider ⇒ Object
Returns the value of attribute provider.
13 14 15 |
# File 'app/models/krikri/field_value_report.rb', line 13 def provider @provider end |
Class Method Details
.fields ⇒ Object
All of the fields for which a report can be created.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/models/krikri/field_value_report.rb', line 32 def self.fields [:dataProvider_providedLabel, :sourceResource_alternative_providedLabel, :sourceResource_collection_title, :sourceResource_contributor_providedLabel, :sourceResource_creator_providedLabel, :sourceResource_date_providedLabel, :sourceResource_description, :sourceResource_format, :sourceResource_genre_providedLabel, :sourceResource_language_providedLabel, :sourceResource_publisher_providedLabel, :sourceResource_rights, :sourceResource_rightsHolder_providedLabel, :sourceResource_spatial_providedLabel, :sourceResource_subject_providedLabel, :sourceResource_temporal, :sourceResource_title, :sourceResource_type_name] end |
.find(field, provider_id) ⇒ Krikri::FieldValueReport
These two params act as a compound key.
22 23 24 25 26 27 28 |
# File 'app/models/krikri/field_value_report.rb', line 22 def self.find(field, provider_id) return nil unless fields.include? field.to_sym provider = Krikri::Provider.find(provider_id) return nil unless provider.present? new({ :field => field, :provider => provider }) end |
Instance Method Details
#enumerate_rows(opts = {}) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/models/krikri/field_value_report.rb', line 65 def enumerate_rows(opts = {}) Enumerator.new do |yielder| loop do opts = query_opts(opts) response = Krikri::SolrResponseBuilder.new(opts).response break if response.docs.empty? parse_solr_response(response).each do |row| yielder << headers.map { |header| row[header] } end opts[:start] += opts[:rows] break if opts[:start] >= response.total end end end |
#headers ⇒ Object
The headers for the report table, and the values to be returned from a Solr query.
56 57 58 |
# File 'app/models/krikri/field_value_report.rb', line 56 def headers [:id, :isShownAt_id, field.to_sym] end |