Class: Sunnyside::PageData
- Inherits:
-
Object
- Object
- Sunnyside::PageData
- 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
Defined Under Namespace
Classes: InvoiceLine
Instance Attribute Summary collapse
-
#invoice_data ⇒ Object
readonly
Returns the value of attribute invoice_data.
-
#page_data ⇒ Object
readonly
Returns the value of attribute page_data.
-
#post_date ⇒ Object
readonly
Returns the value of attribute post_date.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
Instance Method Summary collapse
-
#formatted_provider ⇒ Object
Since the source data is somewhat unreliable in the format, there have been two different variations of AMERIGROUP and ELDERSERVE.
-
#initialize(page_data, post_date) ⇒ PageData
constructor
A new instance of PageData.
- #invoice_lines ⇒ Object
- #provider_missing? ⇒ Boolean
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, post_date) @provider = page_data[/CUSTOMER:\s+(.+)(?=\)')/, 1] @post_date = post_date @page_data = page_data.split(/\n/).select { |line| line =~ /^\([0-9\/]{8}\s/ } end |
Instance Attribute Details
#invoice_data ⇒ Object (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_data ⇒ Object (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_date ⇒ Object (readonly)
Returns the value of attribute post_date.
71 72 73 |
# File 'lib/sunnyside/ledger/ledger.rb', line 71 def post_date @post_date end |
#provider ⇒ Object (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_provider ⇒ Object
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_lines ⇒ Object
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, post_date, client_name) } end |
#provider_missing? ⇒ Boolean
97 98 99 |
# File 'lib/sunnyside/ledger/ledger.rb', line 97 def provider_missing? Provider.where(name: provider).count == 0 end |