Class: QaServer::FetchPresenter
- Inherits:
-
Object
- Object
- QaServer::FetchPresenter
- Defined in:
- app/presenters/qa_server/fetch_presenter.rb
Instance Attribute Summary collapse
-
#authorities_list ⇒ Array<String>
readonly
A list of all loaded authorities’ names.
-
#authority ⇒ String
readonly
Name of authority that was searched.
-
#format ⇒ String
readonly
Format for the returned results of fetching the term.
-
#uri ⇒ String
readonly
The requested URI.
Instance Method Summary collapse
-
#formats_list ⇒ Array<String>
List of supported formats.
-
#initialize(authorities_list:, authority: nil, uri: nil, format: nil, term_results: nil) ⇒ FetchPresenter
constructor
A new instance of FetchPresenter.
- #json? ⇒ Boolean
- #jsonld? ⇒ Boolean
- #n3? ⇒ Boolean
-
#term_results ⇒ String
Results for the term fetch in the requested format.
-
#term_results? ⇒ Boolean
True if search results exist; otherwise false.
Constructor Details
#initialize(authorities_list:, authority: nil, uri: nil, format: nil, term_results: nil) ⇒ FetchPresenter
Returns a new instance of FetchPresenter.
13 14 15 16 17 18 19 |
# File 'app/presenters/qa_server/fetch_presenter.rb', line 13 def initialize(authorities_list:, authority: nil, uri: nil, format: nil, term_results: nil) @authorities_list = .map(&:upcase) @authority = .present? ? .upcase : nil @uri = uri @format = format @term_results = term_results end |
Instance Attribute Details
#authorities_list ⇒ Array<String> (readonly)
Returns A list of all loaded authorities’ names.
23 24 25 |
# File 'app/presenters/qa_server/fetch_presenter.rb', line 23 def @authorities_list end |
#authority ⇒ String (readonly)
Returns Name of authority that was searched.
27 28 29 |
# File 'app/presenters/qa_server/fetch_presenter.rb', line 27 def @authority end |
#format ⇒ String (readonly)
Returns format for the returned results of fetching the term.
40 41 42 |
# File 'app/presenters/qa_server/fetch_presenter.rb', line 40 def format @format end |
#uri ⇒ String (readonly)
Returns The requested URI.
31 32 33 |
# File 'app/presenters/qa_server/fetch_presenter.rb', line 31 def uri @uri end |
Instance Method Details
#formats_list ⇒ Array<String>
Returns list of supported formats.
34 35 36 |
# File 'app/presenters/qa_server/fetch_presenter.rb', line 34 def formats_list ['json', 'jsonld', 'n3'] end |
#json? ⇒ Boolean
42 43 44 |
# File 'app/presenters/qa_server/fetch_presenter.rb', line 42 def json? format.casecmp? 'json' end |
#jsonld? ⇒ Boolean
46 47 48 |
# File 'app/presenters/qa_server/fetch_presenter.rb', line 46 def jsonld? format.casecmp? 'jsonld' end |
#n3? ⇒ Boolean
50 51 52 |
# File 'app/presenters/qa_server/fetch_presenter.rb', line 50 def n3? format.casecmp? 'n3' end |
#term_results ⇒ String
Returns results for the term fetch in the requested format.
55 56 57 58 |
# File 'app/presenters/qa_server/fetch_presenter.rb', line 55 def term_results return JSON.pretty_generate(@term_results) if json? @term_results end |
#term_results? ⇒ Boolean
Returns true if search results exist; otherwise false.
61 62 63 |
# File 'app/presenters/qa_server/fetch_presenter.rb', line 61 def term_results? @term_results.present? end |