Class: Card::DirectorRegister

Inherits:
Object
  • Object
show all
Defined in:
lib/card/director_register.rb

Class Method Summary collapse

Class Method Details

.act_directorObject



45
46
47
48
# File 'lib/card/director_register.rb', line 45

def act_director
  return unless DirectorRegister.act_card
  DirectorRegister.act_card.director
end

.add(director) ⇒ Object



70
71
72
# File 'lib/card/director_register.rb', line 70

def add director
  directors[director.card] = director
end

.card_changed(old_card) ⇒ Object



74
75
76
77
# File 'lib/card/director_register.rb', line 74

def card_changed old_card
  return unless (director = @directors.delete old_card)
  add director
end

.clearObject



54
55
56
57
58
59
60
# File 'lib/card/director_register.rb', line 54

def clear
  DirectorRegister.act_card = nil
  directors.each_pair do |card, _dir|
    card.director = nil
  end
  @directors = nil
end

.deep_delete(director) ⇒ Object



85
86
87
88
89
90
# File 'lib/card/director_register.rb', line 85

def deep_delete director
  director.subdirectors.each do |subdir|
    deep_delete subdir
  end
  delete director
end

.delete(director) ⇒ Object



79
80
81
82
83
# File 'lib/card/director_register.rb', line 79

def delete director
  return unless @directors
  @directors.delete director.card
  director.delete
end

.directorsObject



50
51
52
# File 'lib/card/director_register.rb', line 50

def directors
  @directors ||= {}
end

.fetch(card, opts = {}) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/card/director_register.rb', line 62

def fetch card, opts={}
  return directors[card] if directors[card]
  directors.each_key do |dir_card|
    return dir_card.director if dir_card.name == card.name
  end
  directors[card] = Card.new_director card, opts
end

.running_act?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/card/director_register.rb', line 92

def running_act?
  (dir = DirectorRegister.act_director) && dir.running?
end

.to_sObject



96
97
98
# File 'lib/card/director_register.rb', line 96

def to_s
  directors.values.map(&:to_s).join "\n"
end