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
# 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    = attrs[:description]
  @amended_by     = attrs[:amended_by]
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

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


40
41
42
# File 'lib/fech-search/search_result.rb', line 40

def filing(opts={})
  Fech::Filing.new(self.filing_id, opts)
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



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

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



34
35
36
# File 'lib/fech-search/search_result.rb', line 34

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