Created
December 29, 2018 13:26
-
-
Save gouf/35e2869496dc749014b20c0dfe8a4cfa to your computer and use it in GitHub Desktop.
Faker で適当な JSON データの生成
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
# frozen_string_literal: true | |
require 'faker' | |
require 'json' | |
result = | |
Array.new(100).map do |i| | |
gender = %w[Male Female].sample | |
first_name, last_name = | |
if gender.eql?('Male') | |
[Faker::Name.male_first_name, Faker::Name.last_name] | |
else | |
[Faker::Name.female_first_name, Faker::Name.last_name] | |
end | |
{ | |
'id': i, | |
'firstName': first_name, | |
'lastName': last_name, | |
'gender': gender | |
} | |
end | |
puts result.to_json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment