Module: Card::Name::All

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

Overview

methods connecting Card to Card::Name

Defined Under Namespace

Modules: Descendants, Parts

Instance Method Summary collapse

Methods included from Descendants

#child_ids, #each_child, #each_descendant, #field_ids, #field_names, #fields

Methods included from Parts

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

Instance Method Details

#[](*args) ⇒ Object



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

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



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

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

#field(tag, opts = {}) ⇒ Object



73
74
75
# File 'card/lib/card/name/all.rb', line 73

def field tag, opts={}
  Card.fetch name.field(tag), opts
end

#keyObject



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

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

#key=(newkey) ⇒ Object



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

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



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

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

#nameObject



11
12
13
# File 'card/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



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

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



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

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(cardname) ⇒ Object



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

def update_superleft cardname
  @superleft = @supercard if cardname.field_of? @supercard.name
end