Module: Card::Name::All

Includes:
Descendants, Parts
Included in:
Card
Defined in:
lib/card/name/all.rb,
lib/card/name/all/parts.rb,
lib/card/name/all/descendants.rb

Overview

methods connecting Card to Card::Name

Defined Under Namespace

Modules: Descendants, Parts

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Descendants

#child_ids, #each_child, #each_descendant, #field_cards, #field_ids, #field_names

Methods included from Parts

#left, #left_id=, #left_or_new, #right, #right_id=, #tag, #trunk

Instance Attribute Details

#supercardObject (readonly)

Returns the value of attribute supercard.



10
11
12
# File 'lib/card/name/all.rb', line 10

def supercard
  @supercard
end

Instance Method Details

#[](*args) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/card/name/all.rb', line 29

def [] *args
  case args[0]
  when Integer, Range
    fetch_name = Array.wrap(name.parts[args[0]]).compact.join Name.joint
    Card.fetch(fetch_name, args[1] || {}) unless simple?
  else
    super
  end
end

#autoname(name) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/card/name/all.rb', line 43

def autoname name
  if Card.exists?(name) || Director.include?(name)
    autoname name.next
  else
    name
  end
end

#keyObject



16
17
18
# File 'lib/card/name/all.rb', line 16

def key
  @key ||= left_id ? name.key : super
end

#key=(newkey) ⇒ Object



64
65
66
67
68
69
70
71
72
73
# File 'lib/card/name/all.rb', line 64

def key= newkey
  return if newkey == key

  update_cache_key key do
    write_attribute :key, (name.simple? ? newkey : nil)
    @key = newkey
  end
  clean_patterns
  @key
end

#lexObject



39
40
41
# File 'lib/card/name/all.rb', line 39

def lex
  simple? ? name : [left_id, right_id]
end

#nameObject Also known as: cardname



11
12
13
# File 'lib/card/name/all.rb', line 11

def name
  @name ||= left_id ? Lexicon.lex_to_name([left_id, right_id]) : super.to_name
end

#name=(newname) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/card/name/all.rb', line 20

def name= newname
  @name = superize_name newname.to_name
  self.key = @name.key
  update_subcard_names @name
  write_attribute :name, (@name.simple? ? @name.s : nil)
  assign_side_ids
  @name
end

#update_subcard_names(new_name, name_to_replace = nil) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/card/name/all.rb', line 56

def update_subcard_names new_name, name_to_replace=nil
  return unless @subcards

  subcards.each do |subcard|
    update_subcard_name subcard, new_name, name_to_replace if subcard.new?
  end
end

#update_superleft(newname = nil) ⇒ Object



51
52
53
54
# File 'lib/card/name/all.rb', line 51

def update_superleft newname=nil
  newname ||= name
  @superleft = @supercard if newname.field_of? @supercard.name
end