Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
veNJOB
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Thanh Hung Pham
veNJOB
Commits
a3e43368
Commit
a3e43368
authored
Jul 04, 2017
by
Thanh Hung Pham
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix same merge quest 1
parent
6ab9a5d1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
21 deletions
+15
-21
lib/import/csv_reader.rb
+15
-21
No files found.
lib/import/csv_reader.rb
View file @
a3e43368
...
@@ -18,30 +18,23 @@ class Import::CSVReader
...
@@ -18,30 +18,23 @@ class Import::CSVReader
Thread
.
new
do
Thread
.
new
do
begin
begin
begin
begin
# Area information
Area
.
new
(
name:
'Viet Nam'
).
save
if
Area
.
where
(
name:
'Viet Nam'
).
blank?
Area
.
new
(
name:
'International'
).
save
if
Area
.
where
(
name:
'International'
).
blank?
csv_text
=
File
.
read
(
@file
)
csv_text
=
File
.
read
(
@file
)
csv
=
CSV
.
parse
(
csv_text
,
headers: :true
)
csv
=
CSV
.
parse
(
csv_text
,
headers: :true
)
csv
.
each
do
|
row
|
csv
.
each
do
|
row
|
# Job type information
# Job type information
job_type_name
=
row
[
'type'
].
strip
unless
row
[
'type'
].
nil?
job_type_name
=
row
[
'type'
].
strip
unless
row
[
'type'
].
nil?
job_type
=
JobType
.
find_or_create_by
(
name:
job_type_name
)
job_type
=
JobType
.
new
job_type
.
name
=
job_type_name
job_type
.
save
if
JobType
.
find_by_name
(
job_type_name
).
blank?
# Contact information
# Contact information
contact_name
=
row
[
'contact name'
].
strip
unless
row
[
'contact name'
].
nil?
contact_name
=
row
[
'contact name'
].
strip
unless
row
[
'contact name'
].
nil?
contact_email
=
row
[
'contact email'
].
strip
unless
row
[
'contact email'
].
nil?
contact_email
=
row
[
'contact email'
].
strip
unless
row
[
'contact email'
].
nil?
contact_phone
=
row
[
'contact phone'
].
strip
unless
row
[
'contact phone'
].
nil?
contact_phone
=
row
[
'contact phone'
].
strip
unless
row
[
'contact phone'
].
nil?
contact
=
Contact
.
new
contact
=
Contact
.
find_or_create_by
(
email:
contact_email
)
contact
.
email
=
contact_email
contact
.
email
=
contact_email
contact
.
name
=
contact_name
contact
.
name
=
contact_name
contact
.
phone
=
contact_phone
contact
.
phone
=
contact_phone
contact
.
save
if
Contact
.
find_by_email
(
contact_email
).
blank?
contact
.
save
# Company information
# Company information
company_address
=
row
[
'company address'
].
strip
unless
row
[
'company address'
].
nil?
company_address
=
row
[
'company address'
].
strip
unless
row
[
'company address'
].
nil?
...
@@ -49,27 +42,28 @@ class Import::CSVReader
...
@@ -49,27 +42,28 @@ class Import::CSVReader
company_name
=
row
[
'company name'
].
strip
unless
row
[
'company name'
].
nil?
company_name
=
row
[
'company name'
].
strip
unless
row
[
'company name'
].
nil?
company_province
=
row
[
'company province'
].
strip
unless
row
[
'company province'
].
nil?
company_province
=
row
[
'company province'
].
strip
unless
row
[
'company province'
].
nil?
company
=
Company
.
new
company
=
Company
.
find_or_create_by
(
name:
company_name
)
company
.
address
=
company_address
company
.
address
=
company_address
company
.
district
=
company_district
company
.
district
=
company_district
company
.
name
=
company_name
company
.
name
=
company_name
company
.
province
=
company_province
company
.
province
=
company_province
company
.
save
if
Company
.
find_by_name
(
company_name
).
blank?
company
.
save
# Category information
# Category information
category_name
=
row
[
'category'
].
strip
unless
row
[
'category'
].
nil?
category_name
=
row
[
'category'
].
strip
unless
row
[
'category'
].
nil?
category
=
Category
.
new
category
=
Category
.
find_or_create_by
(
name:
category_name
)
category
.
name
=
category_name
category
.
name
=
category_name
category
.
save
if
Category
.
find_by_name
(
category_name
).
blank?
category
.
save
# City information
# City information
city_name
=
row
[
'work place'
].
strip
unless
row
[
'work place'
].
nil?
city_name
=
row
[
'work place'
].
strip
unless
row
[
'work place'
].
nil?
city_name
=
city_name
.
tr
(
'""'
,
''
).
tr
(
'[]'
,
''
)
# Remove '["text"]' -> 'text'
city
=
City
.
new
city
=
City
.
find_or_create_by
(
name:
city_name
)
city
.
name
=
city_name
city
.
name
=
city_name
city
.
area
=
Area
.
find
(
1
)
city
.
area
=
Area
.
find
_by_name
(
'Viet Nam'
)
city
.
save
if
City
.
find_by_name
(
city_name
).
blank?
city
.
save
# Job information
# Job information
job_benefit
=
row
[
'benefit'
].
strip
unless
row
[
'benefit'
].
nil?
job_benefit
=
row
[
'benefit'
].
strip
unless
row
[
'benefit'
].
nil?
...
@@ -79,7 +73,7 @@ class Import::CSVReader
...
@@ -79,7 +73,7 @@ class Import::CSVReader
job_requirement
=
row
[
'requirement'
].
strip
unless
row
[
'requirement'
].
nil?
job_requirement
=
row
[
'requirement'
].
strip
unless
row
[
'requirement'
].
nil?
job_salary
=
row
[
'salary'
].
strip
unless
row
[
'salary'
].
nil?
job_salary
=
row
[
'salary'
].
strip
unless
row
[
'salary'
].
nil?
job
=
Job
.
new
job
=
Job
.
find_or_create_by
(
name:
job_name
,
city:
city
,
company:
company
)
job
.
benefit
=
job_benefit
job
.
benefit
=
job_benefit
job
.
description
=
job_description
job
.
description
=
job_description
job
.
level
=
job_level
job
.
level
=
job_level
...
@@ -90,13 +84,13 @@ class Import::CSVReader
...
@@ -90,13 +84,13 @@ class Import::CSVReader
job
.
job_type
=
job_type
job
.
job_type
=
job_type
job
.
contact
=
contact
job
.
contact
=
contact
job
.
company
=
company
job
.
company
=
company
job
.
save
if
Job
.
where
(
name:
job_name
,
city:
city
,
company:
company
).
blank?
job
.
save
# Job Category Information
# Job Category Information
job_category
=
JobCategory
.
new
job_category
=
JobCategory
.
find_or_create_by
(
job:
job
,
category:
category
)
job_category
.
job
=
job
job_category
.
job
=
job
job_category
.
category
=
category
job_category
.
category
=
category
job_category
.
save
if
JobCategory
.
where
(
job:
job
,
category:
category
).
blank?
job_category
.
save
end
end
rescue
StandardError
=>
e
rescue
StandardError
=>
e
logger
.
error
(
e
.
message
)
logger
.
error
(
e
.
message
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment