-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CsvService and FileService, and ImportService/Title (#21)
- Loading branch information
1 parent
411595f
commit 2a0e6f2
Showing
3 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require 'csv' | ||
|
||
class CsvService | ||
attr_accessor :filepath, :csv_table | ||
|
||
def initialize(filepath) | ||
@filepath = filepath | ||
@csv_table = CSV.read(filepath, headers: true) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class FileService | ||
def initialize | ||
# TODO: 書く | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module ImportService | ||
class Title | ||
def execute | ||
ActiveRecord::Base.transaction do | ||
::Title.import(columns, values, validate: true) | ||
end | ||
end | ||
|
||
def columns | ||
[:name] | ||
end | ||
|
||
def values | ||
[ | ||
['abc'], | ||
['def'], | ||
] | ||
end | ||
end | ||
end |