DEV Community

Yuta Goto
Yuta Goto

Posted on

1 1

Faker::Rubimasを作ってみた

こんにちは、 .ごっちです。

RubyGem作ったことがなかったので作ってみました。所要時間は4時間くらいです。

fakerというgemとrubimas, faker-precureというgemにインスパイアされています。。

出来上がったもの

https://rubygems.org/gems/faker-rubimas

GitHub logo YutaGoto / faker-rubimas

Test data generator using imas https://github.com/imas/rubimas

Faker::Rubimas

Build Status

Test data generator using 765PRO all stars (include million stars).

This gem is inspired by sue445/faker-precure and imas/rubimas.

Installation

Add this line to your application's Gemfile:

gem 'faker-rubimas'
Enter fullscreen mode Exit fullscreen mode

And then execute:

$ bundle

Or install it yourself as:

$ gem install faker-rubimas

Usage

require 'faker/rubimas'

Faker::Rubimas.name
# => "望月杏奈"

Faker::Rubimas.favorite
# => "ハト"

Faker::Rubimas.hobby
# => "登山"

Faker::Rubimas.talent
# => "ポーカーフェイス"

Faker::Rubimas.idol_type
# => "Princess"

Faker::Rubimas.color
# => "#ffe43f"

Faker::Rubimas.cv
# => "長谷川明子"

Faker::Rubimas.unit_name
# => "クレシェンドブルー"

Faker::Rubimas.unit_member_names
# => ["天海春香", "周防桃子", "福田のり子", "松田亜利沙", "横山奈緒"]
Enter fullscreen mode Exit fullscreen mode

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/YutaGoto/faker-rubimas. This project is intended to be a safe, welcoming space for collaboration, and contributors…

使い方

メソッドを呼び出すたびにそのメソッド名にちなんだ文字列か配列が帰ってきます。

require 'faker/rubimas'

Faker::Rubimas.name
# => "望月杏奈"

Faker::Rubimas.favorite
# => "ハト"

Faker::Rubimas.hobby
# => "登山"

Faker::Rubimas.talent
# => "ポーカーフェイス"

Faker::Rubimas.idol_type
# => "Princess"

Faker::Rubimas.color
# => "#ffe43f"

Faker::Rubimas.cv
# => "長谷川明子"

Faker::Rubimas.unit_name
# => "クレシェンドブルー"

Faker::Rubimas.unit_member_names
# => ["天海春香", "周防桃子", "福田のり子", "松田亜利沙", "横山奈緒"]
Enter fullscreen mode Exit fullscreen mode

苦戦した点

hobbyを持っていないアイドルがいて、ほかのメソッドと同じように書いてたらたまにエラーになってしまうという現象がありました。気づくのに地味に時間がかかりました。。

requrie 'rubimas'

p Rubimas.find_by_name("ジュリア").hobbies
# => nil
Enter fullscreen mode Exit fullscreen mode

なので、hobbyの部分だけ作りが違います。。。

def name
  sample_idol.name.full
end

def hobby
  ::Rubimas.all.map(&:hobbies).flatten.sample
end
Enter fullscreen mode Exit fullscreen mode

--

よければ使ってみてください。

おまけ

Liquid error: internal

Twitterでできたということだけをひとまず報告したら、

faker-rubimas

早くも16ダウンロードあってびっくりしております。

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more