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



39
40
41
42
43
44
45
# File 'lib/card/name/all.rb', line 39

def autoname name
  if Card.exist?(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



60
61
62
63
64
65
66
67
68
69
# File 'lib/card/name/all.rb', line 60

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

#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



52
53
54
55
56
57
58
# File 'lib/card/name/all.rb', line 52

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



47
48
49
50
# File 'lib/card/name/all.rb', line 47

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