Class: FederalRegister::Document

Inherits:
Base show all
Extended by:
DocumentUtilities, Utilities
Defined in:
lib/federal_register/document.rb

Direct Known Subclasses

DocumentImage

Constant Summary

Constants included from DocumentUtilities

FederalRegister::DocumentUtilities::URL_CHARACTER_LIMIT

Constants inherited from Base

Base::INTEGER_CLASS

Instance Attribute Summary

Attributes inherited from Base

#attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DocumentUtilities

find_all

Methods inherited from Base

add_attribute, #fetch_full, #full?, #initialize, override_base_uri

Methods inherited from Client

get

Constructor Details

This class inherits a constructor from FederalRegister::Base

Class Method Details

.find(document_number, options = {}) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/federal_register/document.rb', line 63

def self.find(document_number, options={})
  query = {}
  
  if options[:publication_date].present?
    publication_date = options[:publication_date]
    publication_date = publication_date.is_a?(Date) ? publication_date.to_s(:iso) : publication_date
    
    query.merge!(:publication_date => publication_date)
  end

  if options[:fields].present?
    query.merge!(:fields => options[:fields])
  end

  attributes = get("/documents/#{document_number}.json", :query => query).parsed_response
  new(attributes, :full => true)
end

.find_all_base_pathObject



81
82
83
# File 'lib/federal_register/document.rb', line 81

def self.find_all_base_path
  '/documents'
end

.search(args) ⇒ Object



55
56
57
# File 'lib/federal_register/document.rb', line 55

def self.search(args)
  FederalRegister::ResultSet.fetch("/documents.json", :query => args, :result_class => self)
end

.search_metadata(args) ⇒ Object



59
60
61
# File 'lib/federal_register/document.rb', line 59

def self.(args)
  FederalRegister::ResultSet.fetch("/documents.json", :query => args.merge(:metadata_only => '1'), :result_class => self)
end

Instance Method Details

#agenciesObject



85
86
87
88
89
# File 'lib/federal_register/document.rb', line 85

def agencies
  attributes["agencies"].map do |attr|
    FederalRegister::Agency.new(attr)
  end
end

#imagesObject



103
104
105
106
107
108
109
110
111
# File 'lib/federal_register/document.rb', line 103

def images
  if attributes["images"]
    attributes["images"].map do |attributes|
      FederalRegister::DocumentImage.new(attributes)
    end
  else
    []
  end
end

#page_viewsObject



113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/federal_register/document.rb', line 113

def page_views
  if attributes["page_views"]
    last_updated = begin
      DateTime.parse(attributes["page_views"]["last_updated"])
    rescue
      nil
    end

    {
      count: attributes["page_views"]["count"],
      last_updated: last_updated
    }
  end
end