Module: Card::Name::CardClass

Included in:
Card
Defined in:
lib/card/name/card_class.rb

Overview

Name-related Card class methods

Instance Method Summary collapse

Instance Method Details

#generate_alternative_name(name) ⇒ Object



20
21
22
23
24
# File 'lib/card/name/card_class.rb', line 20

def generate_alternative_name name
  uniq_name = "#{name} 1"
  uniq_name.next! while Card.exist?(uniq_name)
  uniq_name
end

#rename!(oldname, newname) ⇒ Object



5
6
7
# File 'lib/card/name/card_class.rb', line 5

def rename! oldname, newname
  Card[oldname].update! name: newname
end

#uniquify_name(name, rename = :new) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/card/name/card_class.rb', line 9

def uniquify_name name, rename=:new
  name = name.to_name
  return name unless Card.exist? name

  uniq_name = generate_alternative_name name
  return uniq_name unless rename == :old

  rename!(name, uniq_name)
  name
end