[Japanese version Faker] About the gem "gimei"

Background / Profile

I am aiming to get a job at an in-house developed company from inexperienced.

Knowledge level is a level that can be easily developed using Ruby on rails, version control using git, and deployed using heroku. Currently, I'm mainly learning about Ruby on rails, javascript, Docker, AWS, and CircleCI.

Regarding this subject

This time I would like to write about a gem called "gimei" that can be used with Ruby on Rails. "Gimei" is a gem that can be used to generate random Japanese data, such as when writing test code.

I happened to find it while searching for Faker's string generation method. I found it very convenient, so I will introduce it. (* And for my own memorandum.)

What is "gimei"?

"Gimei" creates random Japanese data. For example, fictitious Japanese names and place names.

People who have written test code with rails may have used a gem called "faker", but simply put, "gimei" is a Faker specialized in Japanese. "Faker" is the most famous gem that generates random characters (mainly English), but it doesn't actually support Japanese frigana. Therefore, if you try to generate a character string only with "faker", it is a little inconvenient when writing the test code of the application to be registered with a Japanese name or address. The "gimei" Gem solves that problem.

[Gimei official github] gimei / official

How to use "gimei"

If you look at the formula of gimei, it is explained in Japanese, so I think that explanation is almost unnecessary, but I will write it for the time being. First, let's write it in the Gemfile.

Gemfile


group :development, :test do
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  gem 'rspec-rails', '~> 4.0.0'
  gem 'factory_bot_rails'
  gem 'faker'
  gem 'gimei'
end

As mentioned above, when you use "gimei", you probably use it with "FactoryBot" when testing, so put it in the test group. Then bundle install and you're ready to go. All you have to do is write it in the factories file. You can see that random Japanese is generated on the console.

console


user@user application % rails c
[1] pry(main)> Gimei.last.katakana 
=> "Takeshita"
[2] pry(main)> Gimei.first.katakana
=> "Hart"
[3] pry(main)> Gimei.city.kanji
=> "Ami-cho, Inashiki-gun"

It is like this. It is very convenient because you can easily generate Japanese kanji names and place names. Combining "gimei" and "Faker" can handle most of the random character generation. If you are developing a Japanese application, please use it.

Impressions / Summary

Personally, I'm not very good at English, and I had a hard time reading even the official github of "faker". Either one has to get used to the English literature. .. .. .. However, "gimei" is written in Japanese and the content is simple, so even beginners can easily incorporate it. Please use it.

Recommended Posts

[Japanese version Faker] About the gem "gimei"
About the version of Docker's Node.js image
About the method
About the package
About the error caused by bundle install ~ puma Gem ~
Output about the method # 2
About the StringBuilder class
About Gem :: ConflictError (activesupport)
Commentary: About the interface
About the asset pipeline
About the function double-java
About rails version specification
About the ternary operator
About the length method
About the Kernel module
About the authenticate method.
About the map method
About the ancestors method
[Output] About the database
About the [ruby] operator
About the to_s method.
Gemfile.lock doesn't say the version of gem you have installed
The correct answer for money! The correct answer for silver! [Japanese version of sequence]