Class: ECFS::BulkFilingsQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/ecfs/bulk_filings_query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(docket_number) ⇒ BulkFilingsQuery

Returns a new instance of BulkFilingsQuery.



5
6
7
# File 'lib/ecfs/bulk_filings_query.rb', line 5

def initialize(docket_number)
  @docket_number = docket_number
end

Instance Attribute Details

#resultsObject

Returns the value of attribute results.



3
4
5
# File 'lib/ecfs/bulk_filings_query.rb', line 3

def results
  @results
end

Instance Method Details

#getObject



9
10
11
# File 'lib/ecfs/bulk_filings_query.rb', line 9

def get
  make_query(@docket_number)
end

#get_midpoint(start_date, end_date) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ecfs/bulk_filings_query.rb', line 13

def get_midpoint(start_date, end_date)
  start_date       = start_date.split("/")
  start_date_month = start_date[0].to_i
  start_date_day   = start_date[1].to_i
  start_date_year  = start_date[2].to_i
  docket_started   = Date.new(start_date_year, start_date_month, start_date_day)

  e = end_date.split("/").map(&:to_i).reverse
  difference      = (Date.new(e[0], e[2], e[1]) - docket_started).to_i
  half_difference = difference/2
  midpoint        = (docket_started + half_difference).to_s.gsub("-", "/")

  midpoint.split("/").reverse.join("/")
end

#make_query(docket_number, posted_after = false, posted_before = false) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ecfs/bulk_filings_query.rb', line 28

def make_query(docket_number, posted_after=false, posted_before=false)

  if @results.nil?
    @results = []
  end

  query = ECFS::Filing.query.tap do |q|
    q.docket_number = docket_number
    q.posted_after  = posted_after  if posted_after
    q.posted_before = posted_before if posted_before
  end

  begin
    @results << query.get
  rescue ECFS::TooManyFilingsError
    unless posted_after
      posted_after = ECFS::Proceeding.find(docket_number)["date_created"] 
    end
    unless posted_before
      today = Date.today.to_s.split("-")
      posted_before = today[1] + "/" + today[2] + "/" + today[0]
    end
    midpoint = get_midpoint(posted_after, posted_before).split("/")
    formatted_midpoint = midpoint[1] + "/" + midpoint[0] + "/" + midpoint[2]

    make_query(docket_number, formatted_midpoint, posted_before)
    make_query(docket_number, posted_after, formatted_midpoint)
  end

  @results.flatten!

  @results
end