Created
November 11, 2014 07:23
-
-
Save iorionda/f5fb51281cdc9b6f6c2a to your computer and use it in GitHub Desktop.
宛先を作る
This file contains hidden or 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
require 'faker' | |
require 'spreadsheet' | |
require 'fileutils' | |
require 'i18n' | |
require 'optparse' | |
def parse_options | |
option = {} | |
OptionParser.new do |opt| | |
opt.on('-c VALUE', '--count', 'counts') {|v| option[:size] = v} | |
opt.on('-f VALUE', '--file', 'filename') { |v| option[:name] = v } | |
opt.parse!(ARGV) | |
end | |
option | |
end | |
def create_book(filename, size) | |
I18n.enforce_available_locales = true | |
I18n.default_locale = :en | |
Spreadsheet.client_encoding = "UTF-8" | |
book = Spreadsheet::Workbook.new | |
sheet = book.create_worksheet(name: '宛先') | |
sheet.row(0).concat %w[姓 名 メールアドレス 郵便番号 住所 FAX] | |
1.upto(size.to_i) do |n| | |
sheet[n, 0] = Faker::Name.last_name | |
sheet[n, 1] = Faker::Name.first_name | |
sheet[n, 2] = Faker::Internet.safe_email | |
sheet[n, 3] = "#{[*0...9].sample(3).join}-#{[*0...9].sample(4).join}" | |
sheet[n, 4] = "#{Faker::Address.country} #{Faker::Address.state} #{Faker::Address.city} #{Faker::Address.street_address}" | |
sheet[n, 5] = "0#{[*0...9].sample}-#{[*0...9].sample(4).join}-#{[*0...9].sample(4).join}" | |
end | |
FileUtils.mkdir_p('contacts') | |
book.write "./#{filename}.xls" | |
end | |
option = parse_options | |
create_book(option[:name], option[:size]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment