Class: Fech::Comparison

Inherits:
Object
  • Object
show all
Defined in:
lib/fech/comparison.rb

Overview

Fech::Comparison takes two Filing objects and does comparisons on them, checking for differences between an original and amended filing, or two filings covering the same period in different years.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filing_1, filing_2, opts = {}) ⇒ Comparison

Create a new Comparison object by passing in two Filing objects Filing objects need to be downloaded first f1 = Fech::Filing.new(767437) f1.download f2 = Fech::Filing.new(751798) f2.download comparison = Fech::Comparison.new(f1, f2) comparison.summary



16
17
18
19
# File 'lib/fech/comparison.rb', line 16

def initialize(filing_1, filing_2, opts={})
  @filing_1     = filing_1
  @filing_2     = filing_2
end

Instance Attribute Details

#filing_1Object

Returns the value of attribute filing_1.



6
7
8
# File 'lib/fech/comparison.rb', line 6

def filing_1
  @filing_1
end

#filing_2Object

Returns the value of attribute filing_2.



6
7
8
# File 'lib/fech/comparison.rb', line 6

def filing_2
  @filing_2
end

Instance Method Details

#schedule(schedule) ⇒ Object

compares a schedule of itemized records from one filing to another returns an array of records that are new or have changed.



31
32
33
# File 'lib/fech/comparison.rb', line 31

def schedule(schedule)
  @filing_1.rows_like(schedule.to_sym) - @filing_2.rows_like(schedule.to_sym)
end

#summaryObject

compares summary of this filing with summary of an earlier or later version of the filing, returning a Fech::Mapped hash of mapped fields whose values have changed. based on rails’ hash diff: github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/hash/diff.rb



25
26
27
# File 'lib/fech/comparison.rb', line 25

def summary
  @filing_1.summary.delete_if { |k, v| @filing_2.summary[k] == v }.merge!(@filing_2.summary.dup.delete_if { |k, v| @filing_1.summary.has_key?(k) })
end