Module: Card::Format::Names

Included in:
Card::Format
Defined in:
lib/card/format/names.rb

Instance Method Summary collapse

Instance Method Details

#add_name_context(name = nil) ⇒ Object



28
29
30
31
32
# File 'lib/card/format/names.rb', line 28

def add_name_context name=nil
  name ||= card.name
  @context_names += name.to_name.part_names
  @context_names.uniq!
end

#context_names_from_paramsObject



18
19
20
21
# File 'lib/card/format/names.rb', line 18

def context_names_from_params
  return [] unless (name_list = Card::Env.slot_opts[:name_context])
  name_list.to_s.split(",").map(&:to_name)
end

#context_names_minus_irrelevantsObject



13
14
15
16
# File 'lib/card/format/names.rb', line 13

def context_names_minus_irrelevants
  part_keys = @card.cardname.part_names.map(&:key)
  @context_names.reject { |n| !part_keys.include? n.key }
end

#context_names_to_paramsObject



23
24
25
26
# File 'lib/card/format/names.rb', line 23

def context_names_to_params
  return unless @context_names
  @context_names.join(",")
end

#initial_context_namesObject



4
5
6
7
8
9
10
11
# File 'lib/card/format/names.rb', line 4

def initial_context_names
  @initial_context_names ||=
    if @context_names
      context_names_minus_irrelevants
    else
      context_names_from_params
    end
end

#showname(title = nil) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/card/format/names.rb', line 34

def showname title=nil
  if title
    card.cardname.title title, @context_names
  else
    @showname ||= card.cardname.to_show(*@context_names)
  end
end