Module: Card::Format::ContextNames

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

Instance Method Summary collapse

Instance Method Details

#add_name_context(name = nil) ⇒ Object



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

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

#context_namesObject



5
6
7
# File 'lib/card/format/context_names.rb', line 5

def context_names
  @context_names ||= initial_context_names
end

#context_names_from_paramsObject



19
20
21
22
# File 'lib/card/format/context_names.rb', line 19

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_from_parentObject



14
15
16
17
# File 'lib/card/format/context_names.rb', line 14

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

#context_names_to_paramsObject



24
25
26
27
# File 'lib/card/format/context_names.rb', line 24

def context_names_to_params
  return if context_names.empty?
  context_names.join(",")
end

#initial_context_namesObject



9
10
11
12
# File 'lib/card/format/context_names.rb', line 9

def initial_context_names
  @initial_context_names ||=
    parent ? context_names_from_parent : context_names_from_params
end

#title_in_context(title = nil) ⇒ Object



34
35
36
37
# File 'lib/card/format/context_names.rb', line 34

def title_in_context title=nil
  title = title ? title.to_name.absolute_name(card.cardname) : card.cardname
  title.from *context_names
end