Class: Fech::SearchResult

Inherits:
Object
  • Object
show all
Defined in:
lib/fech-search/search_result.rb

Overview

Fech:SearchResult is a class representing a search result from Fech::Search.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ SearchResult

Returns a new instance of SearchResult.

Parameters:

  • attrs (Hash)

    The attributes of the search result.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/fech-search/search_result.rb', line 9

def initialize(attrs)
  @date_format = '%m/%d/%Y'

  @committee_name = attrs[:committee_name]
  @committee_id   = attrs[:committee_id]
  @filing_id      = attrs[:filing_id].sub(/FEC-/, '').to_i
  @form_type      = attrs[:form_type]
  @period         = parse_period(attrs[:from], attrs[:to])
  @date_filed     = Date.strptime(attrs[:date_filed], @date_format)
  @description    = parse_description(attrs)
  @amended_by     = attrs[:amended_by]
  @amendment      = parse_form_type(attrs[:form_type])
end

Instance Attribute Details

#amended_byObject (readonly)

Returns the value of attribute amended_by.



6
7
8
# File 'lib/fech-search/search_result.rb', line 6

def amended_by
  @amended_by
end

#amendmentObject (readonly)

Returns the value of attribute amendment.



6
7
8
# File 'lib/fech-search/search_result.rb', line 6

def amendment
  @amendment
end

#committee_idObject (readonly)

Returns the value of attribute committee_id.



6
7
8
# File 'lib/fech-search/search_result.rb', line 6

def committee_id
  @committee_id
end

#committee_nameObject (readonly)

Returns the value of attribute committee_name.



6
7
8
# File 'lib/fech-search/search_result.rb', line 6

def committee_name
  @committee_name
end

#date_filedObject (readonly)

Returns the value of attribute date_filed.



6
7
8
# File 'lib/fech-search/search_result.rb', line 6

def date_filed
  @date_filed
end

#descriptionObject (readonly)

Returns the value of attribute description.



6
7
8
# File 'lib/fech-search/search_result.rb', line 6

def description
  @description
end

#filing_idObject (readonly)

Returns the value of attribute filing_id.



6
7
8
# File 'lib/fech-search/search_result.rb', line 6

def filing_id
  @filing_id
end

#form_typeObject (readonly)

Returns the value of attribute form_type.



6
7
8
# File 'lib/fech-search/search_result.rb', line 6

def form_type
  @form_type
end

#periodObject (readonly)

Returns the value of attribute period.



6
7
8
# File 'lib/fech-search/search_result.rb', line 6

def period
  @period
end

Instance Method Details

#filing(opts = {}) ⇒ Fech::Filing

The Fech filing object for this search result

Returns:

  • (Fech::Filing)


68
69
70
# File 'lib/fech-search/search_result.rb', line 68

def filing(opts={})
  Fech::Filing.new(self.filing_id, opts)
end

#parse_description(attrs) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fech-search/search_result.rb', line 34

def parse_description(attrs)
  if attrs[:form_type] == 'F1A' or attrs[:form_type] == 'F1N'
    description = 'STATEMENT OF ORGANIZATION'
  elsif attrs[:form_type] == 'F2A' or attrs[:form_type] == 'F2N'
    description = "STATEMENT OF CANDIDACY"
  elsif attrs[:form_type] == 'F5A' or attrs[:form_type] == 'F5N'
    description = "REPORT OF INDEPENDENT EXPENDITURES MADE"
  elsif attrs[:form_type] == 'F1M'
    description = "NOTIFICATION OF MULTICANDIDATE STATUS"
  elsif attrs[:form_type] == 'F13'
    description = "INAUGURAL COMMITTEE DONATIONS"
  else
    description = attrs[:description].strip
  end
  description
end

#parse_form_type(form_type) ⇒ Object

Checks form_type to see if a filing is an amendment and returns a boolean.



53
54
55
56
57
58
59
# File 'lib/fech-search/search_result.rb', line 53

def parse_form_type(form_type)
  if form_type.end_with?('A')
    true
  else
    false
  end
end

#parse_period(from, to) ⇒ Hash?

Parse the strings representing a filing period. of a filing period.

Parameters:

  • period (String)

    a string representing a filing period

Returns:

  • (Hash, nil)

    a hash representing the start and end



27
28
29
30
31
32
# File 'lib/fech-search/search_result.rb', line 27

def parse_period(from, to)
  return unless valid_date(from.to_s) && valid_date(to.to_s)
  from = Date.strptime(from, @date_format)
  to = Date.strptime(to, @date_format)
  {from: from, to: to}
end

#valid_date(s) ⇒ Object

Check whether a date string is valid



62
63
64
# File 'lib/fech-search/search_result.rb', line 62

def valid_date(s)
  s.match(/\d\d?\/\d\d?\/\d{4}/)
end