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
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 |