Rails mixin to handle address fields

Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
0
down vote
favorite
I'm currently working on a Rails 5.2 application where I'm trying to parse users data into a PDF form. The data from the user is received via a JSON object. The fields of the form are as follow:
'STREET ADDRESS'
'APT'
'CITY'
'STATE'
'ZIP'
However, the when I get the user's address, I get a full string of the address as shown in the following example. (These is a fake address)
"field": "66565235",
"value": "address = 253 Broadway ncity = New Yorknstate = NYnzip = 10003"
So to break that address into street, city, etc. I created a module that I will use as a mixin in the class I created to fill the form fields.
I stored the module in rails_app/pdfs/parse.rb
module Parsing
def parse_address(address)
@address = Indirizzo::Address.new(address)
end
def street
@address.street
end
def city
@address.city
end
def state
@address.state
end
def zip
@address.zip
end
def apt
@address.number
end
end
I named it Parsing because I might want to also add methods to parse phone numbers. The class I created is stored in rails_app/pdfs/pdf_scrie.rb
class PdfScrie < FillablePdfForm
def initialize(user_submission_data)
@user = user_submission_data
super()
end
protected
def fill_out
get_field_names.each do |field_name|
binding.pry
fill field_name, @user.send(field_name)
end
end
end
dictionary =
'1' : '66563XXX', #Is your client applying for SCRIE or DRIE
'2' : '66563XXX', #What agency do you work for?
'3' : '66563XXX', #Initial Application
'4' : '66563XXX', #Name
'DATE OF BIRTH mmddyyyy' : '66563XXX', #Date of Birth
'SOCIAL SECURITY NUMBER' : '66563XXX', #Social Security Number
'STREET ADDRESS' : '66563XXX', #ADDRESS
'APT' : '66563XXX', #Address apt
'CITY' : '66563XXX', #Address CITY
'STATE' : '66563XXX', #Address State
'ZIP' : '66563XXX', #Address ZIP
'TELEPHONE NUMBER area code 1': '66563XXX', #Primary Phone - Area code (000)
'TELEPHONE NUMBER first 3 1' : '66563XXX', #Primary Phone - (000) 000
'TELEPHONE NUMBER Last 4 1' : '66563XXX', #Primary Phone - (000) 000-0000
'CELLPHONE NUMBER area code 1': '66563XXX', #Secondary Phone - Area code (000)
'CELLPHONE NUMBER first 3 1' : '66563XXX', #Secondary Phone - (000) 000
'CELLPHONE NUMBER Last 4 1' : '66563XXX', #Secondary Phone - (000) 000-0000
'EMAIL ADDRESS' : '66564XXX', #Email
'APPLIED IN THE PAST' : '66564XXX', #Have you or your spouse applied for SCRIE in the past?
'NAME FIRST LAST_2' : '66564XXX', #Name
'RELATIONSHIP TO APPLICANT' : '66565XXX', #Relationship to applicant
'ORGANIZATION' : '66564XXX', #Organization
'TELEPHONE NUMBER area code 2': '66564XXX', #Phone - Area code (000)
'TELEPHONE NUMBER first 3 2' : '66564XXX', #Phone - first 3 - (000) 000
'TELEPHONE NUMBER Last 4 2' : '66564XXX', #Phone - last 4 - (000) 000-0000
'STREET ADDRESS_2' : '66564XXX', #ADDRESS 2
'APT_2' : '66564XXX', #Address apt
'CITY_2' : '66564XXX', #Address CITY
'STATE_2' : '66564XXX', #Address State
'ZIP_2' : '66564XXX', #Address ZIP
'EMAIL ADDRESS_2' : '66564XXX', #Email 2
'Applicant Name' : '66563XXX', #Applicant's name
'Veterans Benefits' : '66565XXX', #Your income sources
'Wages' : '66565XXX', #Your income sources
'Pension' : '66565XXX', #Your income sources
'IRAAnnuity Earnings' : '66565XXX', #Your income sources
'Interest' : '66565XXX', #Your income sources
'Capital Gains' : '66565XXX', #Your income sources
'Public Assistance' : '66565XXX', #Your income sources
'Rent paid to you by boarders': '66565XXX', #Your income sources
'Rent paid by Boarders' : '66565XXX', #Your income sources
'Business Income' : '66565XXX', #Your income sources
'Workers Compensation' : '66565XXX', #Your income sources
'Other' : '66565XXX', #Your income sources
'Other_fill-in' : '66565XXX', #Your income sources
'Indicate Retirement Date' : '66565XXX', #Your income sources
'Social Security Administration SSA SSDI SSI' : '66565XXX' #Your income sources
The dictionary is what I'm using to map the PDF form fields to the ID fields of another PDF form that lives in a form service I'm using to process user submissions.
- Should I store the Dictionary somewhere else, if so where?
- I'm I following naming conventions right?
- Can I also add phone parsing methods to the
Parsingmodule, or should I create a seperate module to just parse the phone number? - I'm I following Rails conventions and storing this
modulein the right place? - Am I following correct OOP principles correctly by creating a module that uses an external gem
Indirizzo?
object-oriented ruby ruby-on-rails mixins
add a comment |Â
up vote
0
down vote
favorite
I'm currently working on a Rails 5.2 application where I'm trying to parse users data into a PDF form. The data from the user is received via a JSON object. The fields of the form are as follow:
'STREET ADDRESS'
'APT'
'CITY'
'STATE'
'ZIP'
However, the when I get the user's address, I get a full string of the address as shown in the following example. (These is a fake address)
"field": "66565235",
"value": "address = 253 Broadway ncity = New Yorknstate = NYnzip = 10003"
So to break that address into street, city, etc. I created a module that I will use as a mixin in the class I created to fill the form fields.
I stored the module in rails_app/pdfs/parse.rb
module Parsing
def parse_address(address)
@address = Indirizzo::Address.new(address)
end
def street
@address.street
end
def city
@address.city
end
def state
@address.state
end
def zip
@address.zip
end
def apt
@address.number
end
end
I named it Parsing because I might want to also add methods to parse phone numbers. The class I created is stored in rails_app/pdfs/pdf_scrie.rb
class PdfScrie < FillablePdfForm
def initialize(user_submission_data)
@user = user_submission_data
super()
end
protected
def fill_out
get_field_names.each do |field_name|
binding.pry
fill field_name, @user.send(field_name)
end
end
end
dictionary =
'1' : '66563XXX', #Is your client applying for SCRIE or DRIE
'2' : '66563XXX', #What agency do you work for?
'3' : '66563XXX', #Initial Application
'4' : '66563XXX', #Name
'DATE OF BIRTH mmddyyyy' : '66563XXX', #Date of Birth
'SOCIAL SECURITY NUMBER' : '66563XXX', #Social Security Number
'STREET ADDRESS' : '66563XXX', #ADDRESS
'APT' : '66563XXX', #Address apt
'CITY' : '66563XXX', #Address CITY
'STATE' : '66563XXX', #Address State
'ZIP' : '66563XXX', #Address ZIP
'TELEPHONE NUMBER area code 1': '66563XXX', #Primary Phone - Area code (000)
'TELEPHONE NUMBER first 3 1' : '66563XXX', #Primary Phone - (000) 000
'TELEPHONE NUMBER Last 4 1' : '66563XXX', #Primary Phone - (000) 000-0000
'CELLPHONE NUMBER area code 1': '66563XXX', #Secondary Phone - Area code (000)
'CELLPHONE NUMBER first 3 1' : '66563XXX', #Secondary Phone - (000) 000
'CELLPHONE NUMBER Last 4 1' : '66563XXX', #Secondary Phone - (000) 000-0000
'EMAIL ADDRESS' : '66564XXX', #Email
'APPLIED IN THE PAST' : '66564XXX', #Have you or your spouse applied for SCRIE in the past?
'NAME FIRST LAST_2' : '66564XXX', #Name
'RELATIONSHIP TO APPLICANT' : '66565XXX', #Relationship to applicant
'ORGANIZATION' : '66564XXX', #Organization
'TELEPHONE NUMBER area code 2': '66564XXX', #Phone - Area code (000)
'TELEPHONE NUMBER first 3 2' : '66564XXX', #Phone - first 3 - (000) 000
'TELEPHONE NUMBER Last 4 2' : '66564XXX', #Phone - last 4 - (000) 000-0000
'STREET ADDRESS_2' : '66564XXX', #ADDRESS 2
'APT_2' : '66564XXX', #Address apt
'CITY_2' : '66564XXX', #Address CITY
'STATE_2' : '66564XXX', #Address State
'ZIP_2' : '66564XXX', #Address ZIP
'EMAIL ADDRESS_2' : '66564XXX', #Email 2
'Applicant Name' : '66563XXX', #Applicant's name
'Veterans Benefits' : '66565XXX', #Your income sources
'Wages' : '66565XXX', #Your income sources
'Pension' : '66565XXX', #Your income sources
'IRAAnnuity Earnings' : '66565XXX', #Your income sources
'Interest' : '66565XXX', #Your income sources
'Capital Gains' : '66565XXX', #Your income sources
'Public Assistance' : '66565XXX', #Your income sources
'Rent paid to you by boarders': '66565XXX', #Your income sources
'Rent paid by Boarders' : '66565XXX', #Your income sources
'Business Income' : '66565XXX', #Your income sources
'Workers Compensation' : '66565XXX', #Your income sources
'Other' : '66565XXX', #Your income sources
'Other_fill-in' : '66565XXX', #Your income sources
'Indicate Retirement Date' : '66565XXX', #Your income sources
'Social Security Administration SSA SSDI SSI' : '66565XXX' #Your income sources
The dictionary is what I'm using to map the PDF form fields to the ID fields of another PDF form that lives in a form service I'm using to process user submissions.
- Should I store the Dictionary somewhere else, if so where?
- I'm I following naming conventions right?
- Can I also add phone parsing methods to the
Parsingmodule, or should I create a seperate module to just parse the phone number? - I'm I following Rails conventions and storing this
modulein the right place? - Am I following correct OOP principles correctly by creating a module that uses an external gem
Indirizzo?
object-oriented ruby ruby-on-rails mixins
Welcome to Code Review! It's unclear to me how the various code excerpts work with each other. For example, you've presented us theParsingmodule and thedictionary, but those are not used anywhere in thePdfScrieclass.
â 200_success
Aug 2 at 21:03
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm currently working on a Rails 5.2 application where I'm trying to parse users data into a PDF form. The data from the user is received via a JSON object. The fields of the form are as follow:
'STREET ADDRESS'
'APT'
'CITY'
'STATE'
'ZIP'
However, the when I get the user's address, I get a full string of the address as shown in the following example. (These is a fake address)
"field": "66565235",
"value": "address = 253 Broadway ncity = New Yorknstate = NYnzip = 10003"
So to break that address into street, city, etc. I created a module that I will use as a mixin in the class I created to fill the form fields.
I stored the module in rails_app/pdfs/parse.rb
module Parsing
def parse_address(address)
@address = Indirizzo::Address.new(address)
end
def street
@address.street
end
def city
@address.city
end
def state
@address.state
end
def zip
@address.zip
end
def apt
@address.number
end
end
I named it Parsing because I might want to also add methods to parse phone numbers. The class I created is stored in rails_app/pdfs/pdf_scrie.rb
class PdfScrie < FillablePdfForm
def initialize(user_submission_data)
@user = user_submission_data
super()
end
protected
def fill_out
get_field_names.each do |field_name|
binding.pry
fill field_name, @user.send(field_name)
end
end
end
dictionary =
'1' : '66563XXX', #Is your client applying for SCRIE or DRIE
'2' : '66563XXX', #What agency do you work for?
'3' : '66563XXX', #Initial Application
'4' : '66563XXX', #Name
'DATE OF BIRTH mmddyyyy' : '66563XXX', #Date of Birth
'SOCIAL SECURITY NUMBER' : '66563XXX', #Social Security Number
'STREET ADDRESS' : '66563XXX', #ADDRESS
'APT' : '66563XXX', #Address apt
'CITY' : '66563XXX', #Address CITY
'STATE' : '66563XXX', #Address State
'ZIP' : '66563XXX', #Address ZIP
'TELEPHONE NUMBER area code 1': '66563XXX', #Primary Phone - Area code (000)
'TELEPHONE NUMBER first 3 1' : '66563XXX', #Primary Phone - (000) 000
'TELEPHONE NUMBER Last 4 1' : '66563XXX', #Primary Phone - (000) 000-0000
'CELLPHONE NUMBER area code 1': '66563XXX', #Secondary Phone - Area code (000)
'CELLPHONE NUMBER first 3 1' : '66563XXX', #Secondary Phone - (000) 000
'CELLPHONE NUMBER Last 4 1' : '66563XXX', #Secondary Phone - (000) 000-0000
'EMAIL ADDRESS' : '66564XXX', #Email
'APPLIED IN THE PAST' : '66564XXX', #Have you or your spouse applied for SCRIE in the past?
'NAME FIRST LAST_2' : '66564XXX', #Name
'RELATIONSHIP TO APPLICANT' : '66565XXX', #Relationship to applicant
'ORGANIZATION' : '66564XXX', #Organization
'TELEPHONE NUMBER area code 2': '66564XXX', #Phone - Area code (000)
'TELEPHONE NUMBER first 3 2' : '66564XXX', #Phone - first 3 - (000) 000
'TELEPHONE NUMBER Last 4 2' : '66564XXX', #Phone - last 4 - (000) 000-0000
'STREET ADDRESS_2' : '66564XXX', #ADDRESS 2
'APT_2' : '66564XXX', #Address apt
'CITY_2' : '66564XXX', #Address CITY
'STATE_2' : '66564XXX', #Address State
'ZIP_2' : '66564XXX', #Address ZIP
'EMAIL ADDRESS_2' : '66564XXX', #Email 2
'Applicant Name' : '66563XXX', #Applicant's name
'Veterans Benefits' : '66565XXX', #Your income sources
'Wages' : '66565XXX', #Your income sources
'Pension' : '66565XXX', #Your income sources
'IRAAnnuity Earnings' : '66565XXX', #Your income sources
'Interest' : '66565XXX', #Your income sources
'Capital Gains' : '66565XXX', #Your income sources
'Public Assistance' : '66565XXX', #Your income sources
'Rent paid to you by boarders': '66565XXX', #Your income sources
'Rent paid by Boarders' : '66565XXX', #Your income sources
'Business Income' : '66565XXX', #Your income sources
'Workers Compensation' : '66565XXX', #Your income sources
'Other' : '66565XXX', #Your income sources
'Other_fill-in' : '66565XXX', #Your income sources
'Indicate Retirement Date' : '66565XXX', #Your income sources
'Social Security Administration SSA SSDI SSI' : '66565XXX' #Your income sources
The dictionary is what I'm using to map the PDF form fields to the ID fields of another PDF form that lives in a form service I'm using to process user submissions.
- Should I store the Dictionary somewhere else, if so where?
- I'm I following naming conventions right?
- Can I also add phone parsing methods to the
Parsingmodule, or should I create a seperate module to just parse the phone number? - I'm I following Rails conventions and storing this
modulein the right place? - Am I following correct OOP principles correctly by creating a module that uses an external gem
Indirizzo?
object-oriented ruby ruby-on-rails mixins
I'm currently working on a Rails 5.2 application where I'm trying to parse users data into a PDF form. The data from the user is received via a JSON object. The fields of the form are as follow:
'STREET ADDRESS'
'APT'
'CITY'
'STATE'
'ZIP'
However, the when I get the user's address, I get a full string of the address as shown in the following example. (These is a fake address)
"field": "66565235",
"value": "address = 253 Broadway ncity = New Yorknstate = NYnzip = 10003"
So to break that address into street, city, etc. I created a module that I will use as a mixin in the class I created to fill the form fields.
I stored the module in rails_app/pdfs/parse.rb
module Parsing
def parse_address(address)
@address = Indirizzo::Address.new(address)
end
def street
@address.street
end
def city
@address.city
end
def state
@address.state
end
def zip
@address.zip
end
def apt
@address.number
end
end
I named it Parsing because I might want to also add methods to parse phone numbers. The class I created is stored in rails_app/pdfs/pdf_scrie.rb
class PdfScrie < FillablePdfForm
def initialize(user_submission_data)
@user = user_submission_data
super()
end
protected
def fill_out
get_field_names.each do |field_name|
binding.pry
fill field_name, @user.send(field_name)
end
end
end
dictionary =
'1' : '66563XXX', #Is your client applying for SCRIE or DRIE
'2' : '66563XXX', #What agency do you work for?
'3' : '66563XXX', #Initial Application
'4' : '66563XXX', #Name
'DATE OF BIRTH mmddyyyy' : '66563XXX', #Date of Birth
'SOCIAL SECURITY NUMBER' : '66563XXX', #Social Security Number
'STREET ADDRESS' : '66563XXX', #ADDRESS
'APT' : '66563XXX', #Address apt
'CITY' : '66563XXX', #Address CITY
'STATE' : '66563XXX', #Address State
'ZIP' : '66563XXX', #Address ZIP
'TELEPHONE NUMBER area code 1': '66563XXX', #Primary Phone - Area code (000)
'TELEPHONE NUMBER first 3 1' : '66563XXX', #Primary Phone - (000) 000
'TELEPHONE NUMBER Last 4 1' : '66563XXX', #Primary Phone - (000) 000-0000
'CELLPHONE NUMBER area code 1': '66563XXX', #Secondary Phone - Area code (000)
'CELLPHONE NUMBER first 3 1' : '66563XXX', #Secondary Phone - (000) 000
'CELLPHONE NUMBER Last 4 1' : '66563XXX', #Secondary Phone - (000) 000-0000
'EMAIL ADDRESS' : '66564XXX', #Email
'APPLIED IN THE PAST' : '66564XXX', #Have you or your spouse applied for SCRIE in the past?
'NAME FIRST LAST_2' : '66564XXX', #Name
'RELATIONSHIP TO APPLICANT' : '66565XXX', #Relationship to applicant
'ORGANIZATION' : '66564XXX', #Organization
'TELEPHONE NUMBER area code 2': '66564XXX', #Phone - Area code (000)
'TELEPHONE NUMBER first 3 2' : '66564XXX', #Phone - first 3 - (000) 000
'TELEPHONE NUMBER Last 4 2' : '66564XXX', #Phone - last 4 - (000) 000-0000
'STREET ADDRESS_2' : '66564XXX', #ADDRESS 2
'APT_2' : '66564XXX', #Address apt
'CITY_2' : '66564XXX', #Address CITY
'STATE_2' : '66564XXX', #Address State
'ZIP_2' : '66564XXX', #Address ZIP
'EMAIL ADDRESS_2' : '66564XXX', #Email 2
'Applicant Name' : '66563XXX', #Applicant's name
'Veterans Benefits' : '66565XXX', #Your income sources
'Wages' : '66565XXX', #Your income sources
'Pension' : '66565XXX', #Your income sources
'IRAAnnuity Earnings' : '66565XXX', #Your income sources
'Interest' : '66565XXX', #Your income sources
'Capital Gains' : '66565XXX', #Your income sources
'Public Assistance' : '66565XXX', #Your income sources
'Rent paid to you by boarders': '66565XXX', #Your income sources
'Rent paid by Boarders' : '66565XXX', #Your income sources
'Business Income' : '66565XXX', #Your income sources
'Workers Compensation' : '66565XXX', #Your income sources
'Other' : '66565XXX', #Your income sources
'Other_fill-in' : '66565XXX', #Your income sources
'Indicate Retirement Date' : '66565XXX', #Your income sources
'Social Security Administration SSA SSDI SSI' : '66565XXX' #Your income sources
The dictionary is what I'm using to map the PDF form fields to the ID fields of another PDF form that lives in a form service I'm using to process user submissions.
- Should I store the Dictionary somewhere else, if so where?
- I'm I following naming conventions right?
- Can I also add phone parsing methods to the
Parsingmodule, or should I create a seperate module to just parse the phone number? - I'm I following Rails conventions and storing this
modulein the right place? - Am I following correct OOP principles correctly by creating a module that uses an external gem
Indirizzo?
object-oriented ruby ruby-on-rails mixins
edited Aug 2 at 20:59
200_success
123k14143398
123k14143398
asked Aug 2 at 18:33
theasteve
1
1
Welcome to Code Review! It's unclear to me how the various code excerpts work with each other. For example, you've presented us theParsingmodule and thedictionary, but those are not used anywhere in thePdfScrieclass.
â 200_success
Aug 2 at 21:03
add a comment |Â
Welcome to Code Review! It's unclear to me how the various code excerpts work with each other. For example, you've presented us theParsingmodule and thedictionary, but those are not used anywhere in thePdfScrieclass.
â 200_success
Aug 2 at 21:03
Welcome to Code Review! It's unclear to me how the various code excerpts work with each other. For example, you've presented us the
Parsing module and the dictionary, but those are not used anywhere in the PdfScrie class.â 200_success
Aug 2 at 21:03
Welcome to Code Review! It's unclear to me how the various code excerpts work with each other. For example, you've presented us the
Parsing module and the dictionary, but those are not used anywhere in the PdfScrie class.â 200_success
Aug 2 at 21:03
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f200849%2frails-mixin-to-handle-address-fields%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Welcome to Code Review! It's unclear to me how the various code excerpts work with each other. For example, you've presented us the
Parsingmodule and thedictionary, but those are not used anywhere in thePdfScrieclass.â 200_success
Aug 2 at 21:03