Class: Ecfr::VersionerService::Topic

Inherits:
Base
  • Object
show all
Extended by:
ResponseHelper
Defined in:
lib/ecfr/versioner_service/topic.rb,
lib/ecfr/testing/extensions/versioner_service/topic_extensions.rb

Overview

Topics represent entries in the CFR Index and Finding Aids.

Each topic contains a name and may have references to specific CFR sections, see_also references to other topics, or see references for redirects.

Constant Summary collapse

TOPICS_PATH =

/current | /2024

"v1/topics"

Instance Attribute Summary collapse

Class Method Summary collapse

Methods included from ResponseHelper

stubbed_response

Methods inherited from Base

base_url, service_name, service_path

Instance Attribute Details

#adhocBoolean (readonly)

distinguish informal topics from thesaurus entries

Returns:

  • (Boolean)


13
14
15
# File 'lib/ecfr/versioner_service/topic.rb', line 13

attribute :adhoc,
type: :boolean,
desc: "distinguish informal topics from thesaurus entries"

#agencies[Ecfr::VersionerService::Agency] (readonly)

array of agencies referenced in topics



39
40
41
# File 'lib/ecfr/versioner_service/topic.rb', line 39

 :agencies,
type: Array(Ecfr::VersionerService::Agency),
desc: "array of agencies referenced in topics"

#nameString (readonly)

name of the topic

Returns:

  • (String)


17
18
# File 'lib/ecfr/versioner_service/topic.rb', line 17

attribute :name,
desc: "name of the topic"

#references[Ecfr::VersionerService::Reference] (readonly)

array of CFR references with descriptions



20
21
22
# File 'lib/ecfr/versioner_service/topic.rb', line 20

 :references,
type: Array(Ecfr::VersionerService::Reference),
desc: "array of CFR references with descriptions"

#see[:string] (readonly)

array of topic names to redirect to

Returns:

  • ([:string])


28
29
30
# File 'lib/ecfr/versioner_service/topic.rb', line 28

attribute :see,
type: Array(:string),
desc: "array of topic names to redirect to"

#see_also[:string] (readonly)

array of related topic names to see also

Returns:

  • ([:string])


24
25
26
# File 'lib/ecfr/versioner_service/topic.rb', line 24

attribute :see_also,
type: Array(:string),
desc: "array of related topic names to see also"

#slugString (readonly)

normalized topic identifier for URLs

Returns:

  • (String)


32
33
# File 'lib/ecfr/versioner_service/topic.rb', line 32

attribute :slug,
desc: "normalized topic identifier for URLs"

Class Method Details

.all(options = {}) ⇒ <Topic>

Retrieves the list of all Topics

Parameters:

  • options (<Hash>) (defaults to: {})

Options Hash (options):

  • :year (String) — default: "current"

    the year or 'current' to retrieve topics for

  • :include_agencies (Boolean) — default: false

    whether to include agencies in the response

Returns:

  • (<Topic>)

    array of Topics with their references and relationships



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ecfr/versioner_service/topic.rb', line 56

def self.all(options = {})
  year = options.fetch(:year, "current")
  include_agencies = options.fetch(:include_agencies, false)

  params = {}
  params[:include_agencies] = true if include_agencies

  perform(
    :get,
    "#{TOPICS_PATH}/#{year}",
    params: params,
    perform_options: {
      attributes_key: nil
    }
  )
end

.response_for(topics, meta: {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/ecfr/testing/extensions/versioner_service/topic_extensions.rb', line 4

def self.response_for(topics, meta: {})
  topics = topics.is_a?(Array) ? topics : [topics]

  results = {
    topics: topics,
    meta: meta
  }.compact

  build(
    response: stubbed_response(results.to_json)
  )
end