Class: FederalRegister::Base

Inherits:
Client
  • Object
show all
Defined in:
lib/federal_register/base.rb

Direct Known Subclasses

Agency, Article, PublicInspectionDocument

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Client

get

Constructor Details

#initialize(attributes = {}, options = {}) ⇒ Base

Returns a new instance of Base.



36
37
38
39
# File 'lib/federal_register/base.rb', line 36

def initialize(attributes = {}, options = {})
  @attributes = attributes
  @full = options[:full] || false
end

Instance Attribute Details

#attributesObject (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



4
5
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
# File 'lib/federal_register/base.rb', line 4

def self.add_attribute(*attributes)
  options = {}

  if attributes.last.is_a?(Hash)
    options = attributes.pop
  end

  attributes.each do |attr|
    define_method attr do
      val = @attributes[attr.to_s]
      if val
        case options[: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?(Fixnum)
            val = val.to_i
          end
        end
      end

      val
    end
  end
end

.override_base_uri(uri) ⇒ Object



51
52
53
54
55
# File 'lib/federal_register/base.rb', line 51

def self.override_base_uri(uri)
  [FederalRegister::Agency, FederalRegister::Article, FederalRegister::Base, FederalRegister::Client, FederalRegister:: ResultSet].each do |klass|
    klass.base_uri(uri)
  end
end

Instance Method Details

#fetch_fullObject



45
46
47
48
49
# File 'lib/federal_register/base.rb', line 45

def fetch_full
  @attributes = self.class.get(json_url)
  @full = true
  self
end

#full?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/federal_register/base.rb', line 41

def full?
  @full
end