Class: Sunnyside::PageData

Inherits:
Object
  • Object
show all
Defined in:
lib/sunnyside/ledger/ledger.rb

Overview

in PageData, the providers name is captured from the PDF::Reader raw_content, and the post date from the file name. the rest of the data (the invoices) gets split by newlines (filted by those lines that fit the criteria for invoice data) Then, the data gets finalized (via the InvoiceLine child class of PageData) and inserted into the database.

Direct Known Subclasses

InvoiceLine

Defined Under Namespace

Classes: InvoiceLine

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page_data, post_date) ⇒ PageData

Returns a new instance of PageData.



73
74
75
76
77
# File 'lib/sunnyside/ledger/ledger.rb', line 73

def initialize(page_data, )
  @provider  = page_data[/CUSTOMER:\s+(.+)(?=\)')/, 1]
  @post_date = 
  @page_data = page_data.split(/\n/).select { |line| line =~ /^\([0-9\/]{8}\s/ }
end

Instance Attribute Details

#invoice_dataObject (readonly)

Returns the value of attribute invoice_data.



71
72
73
# File 'lib/sunnyside/ledger/ledger.rb', line 71

def invoice_data
  @invoice_data
end

#page_dataObject (readonly)

Returns the value of attribute page_data.



71
72
73
# File 'lib/sunnyside/ledger/ledger.rb', line 71

def page_data
  @page_data
end

#post_dateObject (readonly)

Returns the value of attribute post_date.



71
72
73
# File 'lib/sunnyside/ledger/ledger.rb', line 71

def 
  @post_date
end

#providerObject (readonly)

Returns the value of attribute provider.



71
72
73
# File 'lib/sunnyside/ledger/ledger.rb', line 71

def provider
  @provider
end

Instance Method Details

#formatted_providerObject

Since the source data is somewhat unreliable in the format, there have been two different variations of AMERIGROUP and ELDERSERVE. This method accounts for the aberrations while still maintaining that any provider not recognized by the DB to be saved as a PRIVATE client.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/sunnyside/ledger/ledger.rb', line 82

def formatted_provider
  if provider_missing?
    case provider
    when 'ELDERSERVEHEALTH'
      Provider[5]
    when 'AMERIGROUP'
      Provider[1]
    else
      Provider[16]
    end
  else
    Provider.where(name: provider).first
  end
end

#invoice_linesObject



101
102
103
104
105
106
107
108
# File 'lib/sunnyside/ledger/ledger.rb', line 101

def invoice_lines
  page_data.map { |line|
    line.gsub!(/^\(|\)'/)
    line.gsub!("\x00", " ")
    client_name = line.slice!(20..45)
    line        = InvoiceLine.new(line, formatted_provider, , client_name) 
  }
end

#provider_missing?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/sunnyside/ledger/ledger.rb', line 97

def provider_missing?
  Provider.where(name: provider).count == 0
end