Class: QaServer::FetchPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/qa_server/fetch_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(authorities_list:, authority: nil, uri: nil, format: nil, term_results: nil) ⇒ FetchPresenter

Returns a new instance of FetchPresenter.

Parameters:

  • authorities_list (Array<String>) —

    a list of all loaded authorities' names

  • authority (String) (defaults to: nil) —

    name of the authority from which the term was fetched (e.g. 'LOCSUBJECT_LD4L_CACHE')

  • uri (String) (defaults to: nil) —

    requested URI (e.g. 'http://id.loc.gov/authorities/subjects/sh2003008312')

  • format (String) (defaults to: nil) —

    return results in this format (e.g. 'json', 'jsonld', 'n3')

  • term_results (String) (defaults to: nil) —

    results of fetching a term in the requested format



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 = authorities_list.map(&:upcase)
  @authority = authority.present? ? authority.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.

Examples:

['AGROVOC_DIRECT', 'AGROVOC_LD4L_CACHE', 'LOCNAMES_LD4L_CACHE']

Returns:

  • (Array<String>) —

    A list of all loaded authorities' names



23
24
25
# File 'app/presenters/qa_server/fetch_presenter.rb', line 23

def authorities_list
  @authorities_list
end

#authority ⇒ String (readonly)

Returns Name of authority that was searched.

Examples:

'AGROVOC_LD4L_CACHE'

Returns:

  • (String) —

    Name of authority that was searched



27
28
29
# File 'app/presenters/qa_server/fetch_presenter.rb', line 27

def authority
  @authority
end

#format ⇒ String (readonly)

Returns format for the returned results of fetching the term.

Examples:

'json', 'jsonld', 'n3'

Returns:

  • (String) —

    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.

Examples:

'http://id.loc.gov/authorities/subjects/sh2003008312'

Returns:

  • (String) —

    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.

Returns:

  • (Array<String>) —

    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

Returns:

  • (Boolean)


42
43
44
# File 'app/presenters/qa_server/fetch_presenter.rb', line 42

def json?
  format.casecmp? 'json'
end

#jsonld? ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'app/presenters/qa_server/fetch_presenter.rb', line 46

def jsonld?
  format.casecmp? 'jsonld'
end

#n3? ⇒ Boolean

Returns:

  • (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.

Returns:

  • (String) —

    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.

Returns:

  • (Boolean) —

    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