Class: FederalRegister::Base
- Defined in:
- lib/federal_register/base.rb
Direct Known Subclasses
Agency, Document, DocumentSearchDetails, Facet, Facet::PublicInspectionIssue, HighlightedDocument, PublicInspectionDocument, PublicInspectionDocumentSearchDetails, Section, SuggestedSearch, Topic
Constant Summary collapse
- INTEGER_CLASS =
1.class
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Class Method Summary collapse
- .add_attribute(*attributes) ⇒ Object
-
.override_base_uri(uri) ⇒ Object
this has to be done because HTTParty uses a custom attr_inheritable which copies the setting for base uri into each class at inheritance time - which is before we can modify it in something like a Rails initializer.
Instance Method Summary collapse
- #fetch_full ⇒ Object
- #full? ⇒ Boolean
-
#initialize(attributes = {}, options = {}) ⇒ Base
constructor
A new instance of Base.
Methods inherited from Client
Constructor Details
#initialize(attributes = {}, options = {}) ⇒ Base
Returns a new instance of Base.
38 39 40 41 |
# File 'lib/federal_register/base.rb', line 38 def initialize(attributes = {}, = {}) @attributes = attributes @full = [:full] || false end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
2 3 4 |
# File 'lib/federal_register/base.rb', line 2 def attributes @attributes end |
Class Method Details
.add_attribute(*attributes) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/federal_register/base.rb', line 6 def self.add_attribute(*attributes) = {} if attributes.last.is_a?(Hash) = attributes.pop end attributes.each do |attr| define_method attr do val = @attributes[attr.to_s] if val case [:type] when :date if ! val.is_a?(Date) val = Date.strptime(val.to_s) end when :datetime if ! val.is_a?(DateTime) val = DateTime.parse(val.to_s) end when :integer if ! val.is_a?(INTEGER_CLASS) val = val.to_i end end end val end end end |
.override_base_uri(uri) ⇒ Object
this has to be done because HTTParty uses a custom attr_inheritable which copies the setting for base uri into each class at inheritance time - which is before we can modify it in something like a Rails initializer
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/federal_register/base.rb', line 57 def self.override_base_uri(uri) [ FederalRegister::Agency, FederalRegister::Article, FederalRegister::Base, FederalRegister::Client, FederalRegister::Document, FederalRegister::DocumentImage, FederalRegister::DocumentSearchDetails, FederalRegister::Facet, FederalRegister::Facet::Agency, FederalRegister::Facet::PresidentialDocumentType, FederalRegister::Facet::Topic, FederalRegister::Facet::Document::Frequency, FederalRegister::Facet::Document::Daily, FederalRegister::Facet::Document::Weekly, FederalRegister::Facet::Document::Monthly, FederalRegister::Facet::Document::Quarterly, FederalRegister::Facet::Document::Yearly, FederalRegister::Facet::Document::Agency, FederalRegister::Facet::Document::Section, FederalRegister::Facet::Document::Topic, FederalRegister::Facet::Document::Type, FederalRegister::Facet::PublicInspectionDocument, FederalRegister::PublicInspectionDocumentSearchDetails, FederalRegister::Facet::PublicInspectionDocument::Agencies, FederalRegister::Facet::PublicInspectionDocument::Agency, FederalRegister::Facet::PublicInspectionDocument::Type, FederalRegister::Facet::PublicInspectionIssue, FederalRegister::Facet::PublicInspectionIssue::Daily, FederalRegister::Facet::PublicInspectionIssue::DailyFiling, FederalRegister::Facet::PublicInspectionIssue::Type, FederalRegister::Facet::PublicInspectionIssue::TypeFiling, FederalRegister::HighlightedDocument, FederalRegister::PublicInspectionDocument, FederalRegister::Section, FederalRegister::SuggestedSearch, FederalRegister::Topic, FederalRegister::ResultSet, FederalRegister::PublicInspectionIssueResultSet, FederalRegister::FacetResultSet, ].each do |klass| klass.base_uri(uri) end end |
Instance Method Details
#fetch_full ⇒ Object
47 48 49 50 51 |
# File 'lib/federal_register/base.rb', line 47 def fetch_full @attributes = self.class.get(json_url).fetch_full @full = true self end |
#full? ⇒ Boolean
43 44 45 |
# File 'lib/federal_register/base.rb', line 43 def full? @full end |