Class: CongressForms::Form

Inherits:
Object
  • Object
show all
Defined in:
lib/congress_forms/form.rb

Direct Known Subclasses

CwcForm, WebForm

Constant Summary collapse

@@repo =
nil

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find(form_id) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/congress_forms/form.rb', line 13

def self.find(form_id)
  begin
    cwc_client = Cwc::Client.new
  rescue KeyError => _
    nil
  end

  if (cwc_client&.office_supported?(form_id) rescue nil)
    CwcForm.new(form_id)
  else
    content, timestamp = repo.find("members/#{form_id}.yaml")
    WebForm.parse(content, updated_at: timestamp)
  end
rescue Errno::ENOENT => e
  nil
end

.repoObject



5
6
7
8
9
10
11
# File 'lib/congress_forms/form.rb', line 5

def self.repo
  @@repo ||=
    Repo.new(CongressForms.contact_congress_remote).tap do |repo|
      repo.location = CongressForms.contact_congress_repository
      repo.auto_update = CongressForms.auto_update_contact_congress?
    end
end

Instance Method Details

#missing_required_params(params) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/congress_forms/form.rb', line 30

def missing_required_params(params)
  missing_parameters = []

  required_params.each do |field|
    unless params.include?(field[:value])
      missing_parameters << field[:value]
    end
  end

  missing_parameters.empty? ? nil : missing_parameters.any
end