Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve Idol#find_by_name #4

Merged
merged 3 commits into from
Dec 5, 2016
Merged

Conversation

gomao9
Copy link
Contributor

@gomao9 gomao9 commented Dec 5, 2016

example:

[1] pry(main)> require 'rubimas'
=> true
[2] pry(main)> Rubimas.find_by_name("美也").color
=> "#d7a96b"

Copy link
Member

@treby treby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your pr! It's a good idea for extend method. I have few advices.

case idol_name
when Symbol
all_idols.find { |idol| idol.key == idol_name } || raise("unknown idol: #{idol_name}")
when String
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about the code below? I think we can decrease code volume.

all_idols.find do |idol|
  [idol.key, idol.name.given, idol.name.aka, idol.name.full].include?(idol_name) || raise("unknown idol: #{idol_name}")
end

or we can extend Idol::Name#== method like below

def ==(other)
  super || [aka, family, full].compact.include?(other)
end

and can write find_by_name method like this.

all_idols.find { |idol| [idol.key, idol.name].include? idol_name } || raise("unknown idol: #{idol_name}")

How do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the second idea is better. I'll try it.

context 'can find idol' do
where(:name, :expected) do
[
[ "未来", :mirai],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove space: [ " -> ["

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for pointing out. I'll fix it.

Copy link
Member

@treby treby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@treby treby merged commit 50a029f into imas:master Dec 5, 2016
@gomao9 gomao9 deleted the improve-find_by_name branch December 6, 2016 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants