Class: AcademicBenchmarks::Api::Standards
- Inherits:
-
Object
- Object
- AcademicBenchmarks::Api::Standards
- Defined in:
- lib/academic_benchmarks/api/standards.rb
Constant Summary collapse
- DEFAULT_PER_PAGE =
100
Instance Method Summary collapse
- #all ⇒ Object
- #authorities(query_params = {}) ⇒ Object
- #authority_documents(authority_or_auth_code_guid_or_desc) ⇒ Object
- #authority_tree(authority_or_auth_code_guid_or_desc, include_obsolete_standards: true) ⇒ Object
- #document_tree(document_or_guid, include_obsolete_standards: true) ⇒ Object
- #documents(query_params = {}) ⇒ Object
- #guid(guid, fields: []) ⇒ Object
-
#initialize(handle) ⇒ Standards
constructor
A new instance of Standards.
- #search(opts = {}) ⇒ Object (also: #where)
Constructor Details
#initialize(handle) ⇒ Standards
Returns a new instance of Standards.
11 12 13 |
# File 'lib/academic_benchmarks/api/standards.rb', line 11 def initialize(handle) @handle = handle end |
Instance Method Details
#all ⇒ Object
48 49 50 |
# File 'lib/academic_benchmarks/api/standards.rb', line 48 def all request_search_pages_and_concat_resources(auth_query_params) end |
#authorities(query_params = {}) ⇒ Object
52 53 54 55 56 |
# File 'lib/academic_benchmarks/api/standards.rb', line 52 def (query_params = {}) raw_search({list: "authority"}.merge(query_params)).map do |a| AcademicBenchmarks::Standards::Authority.from_hash(a["data"]["authority"]) end end |
#authority_documents(authority_or_auth_code_guid_or_desc) ⇒ Object
64 65 66 67 |
# File 'lib/academic_benchmarks/api/standards.rb', line 64 def () = auth_from_code_guid_or_desc() documents(authority: .code) end |
#authority_tree(authority_or_auth_code_guid_or_desc, include_obsolete_standards: true) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/academic_benchmarks/api/standards.rb', line 69 def (, include_obsolete_standards: true) = auth_from_code_guid_or_desc() auth_children = search(authority: .code) AcademicBenchmarks::Standards::StandardsForest.new( auth_children, include_obsoletes: include_obsolete_standards ).consolidate_under_root() end |
#document_tree(document_or_guid, include_obsolete_standards: true) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/academic_benchmarks/api/standards.rb', line 78 def document_tree(document_or_guid, include_obsolete_standards: true) document = doc_from_guid(document_or_guid) doc_children = search(document: document.guid) AcademicBenchmarks::Standards::StandardsForest.new( doc_children, include_obsoletes: include_obsolete_standards ).consolidate_under_root(document) end |
#documents(query_params = {}) ⇒ Object
58 59 60 61 62 |
# File 'lib/academic_benchmarks/api/standards.rb', line 58 def documents(query_params = {}) raw_search({list: "document"}.merge(query_params)).map do |a| AcademicBenchmarks::Standards::Document.from_hash(a["data"]["document"]) end end |
#guid(guid, fields: []) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/academic_benchmarks/api/standards.rb', line 32 def guid(guid, fields: []) query_params = if fields.empty? auth_query_params else auth_query_params.merge({ fields: fields.join(",") }) end @handle.class.get( "/standards/#{guid}", query: query_params ).parsed_response["resources"].map do |r| AcademicBenchmarks::Standards::Standard.new(r["data"]) end end |
#search(opts = {}) ⇒ Object Also known as: where
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/academic_benchmarks/api/standards.rb', line 15 def search(opts = {}) # query: "", authority: "", subject: "", grade: "", subject_doc: "", course: "", # document: "", parent: "", deepest: "", limit: -1, offset: -1, list: "", fields: [] invalid_params = invalid_search_params(opts) if invalid_params.empty? raw_search(opts).map do |standard| AcademicBenchmarks::Standards::Standard.new(standard) end else raise ArgumentError.new( "Invalid search params: #{invalid_params.join(', ')}" ) end end |