Created
August 3, 2013 04:19
-
-
Save supermomonga/6145165 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
# -*- encoding: utf-8 -*- | |
require 'nkf' | |
class Idol | |
attr_reader :name | |
def initialize(name) | |
@name = NKF::nkf('-wxZ4', name) # zenkaku to hankaku | |
@nicknames = {} | |
insert_nicknames({ | |
'しぶりん' => '渋谷凛', | |
'うずりん' => '島村卯月', | |
'ニート' => '双葉杏', | |
'さっちゃん' => '輿水幸子' | |
}) | |
end | |
def insert_nickname(nickname, name) | |
@nicknames[NKF::nkf('-wxZ4', nickname)] = name | |
end | |
def insert_nicknames(d) | |
d.map do |k,v| | |
insert_nickname(k,v) | |
end | |
end | |
def request_name | |
@nicknames[split_rarity] ? @nicknames[split_rarity] : split_rarity | |
end | |
def plus? | |
/[+]$/ =~ @name | |
end | |
def split_plus | |
plus? ? @name[0...-1] : @name | |
end | |
def split_rarity | |
split_plus.match(/(\W+)\w*/)[1] | |
end | |
def rarity | |
rarity = | |
case split_plus.match(/\W+(\w*)/)[1] | |
when 'SR'; 'SR' | |
when 'R'; 'R' | |
when 'N'; 'N' | |
else 'U' #unknown or nothing | |
end | |
plus? ? rarity + '+' : rarity | |
end | |
end | |
idol = Idol.new('しぶりんR+') | |
p idol.request_name, idol.rarity | |
idol = Idol.new('しぶりんR+') | |
p idol.request_name, idol.rarity | |
idol = Idol.new('ニートR+') | |
p idol.request_name, idol.rarity | |
idol = Idol.new('ニートR+') | |
p idol.request_name, idol.rarity | |
idol = Idol.new('さっちゃんSR') | |
p idol.request_name, idol.rarity | |
idol = Idol.new('[ピュアバレンタイン]渋谷凛+') | |
p idol.request_name, idol.rarity |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment