Module: Card::Format::Names
- Included in:
- Card::Format
- Defined in:
- lib/card/format/names.rb
Instance Method Summary collapse
- #add_name_context(name = nil) ⇒ Object
- #context_names_from_params ⇒ Object
- #context_names_minus_irrelevants ⇒ Object
- #context_names_to_params ⇒ Object
- #initial_context_names ⇒ Object
-
#showname(title = nil) ⇒ Object
def with_name_context name old_context = @context_names add_name_context name result = yield @context_names = old_context result end.
Instance Method Details
#add_name_context(name = nil) ⇒ Object
30 31 32 33 34 |
# File 'lib/card/format/names.rb', line 30 def add_name_context name=nil name ||= card.name @context_names += name.to_name.part_names @context_names.uniq! end |
#context_names_from_params ⇒ Object
20 21 22 23 |
# File 'lib/card/format/names.rb', line 20 def context_names_from_params context_name_list = params[:slot][:name_context].to_s context_name_list.split(",").map(&:to_name) end |
#context_names_minus_irrelevants ⇒ Object
15 16 17 18 |
# File 'lib/card/format/names.rb', line 15 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_params ⇒ Object
25 26 27 28 |
# File 'lib/card/format/names.rb', line 25 def context_names_to_params return unless @context_names @context_names.join(",") end |
#initial_context_names ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/card/format/names.rb', line 4 def initial_context_names @initial_context_names ||= if @context_names context_names_minus_irrelevants elsif params[:slot] context_names_from_params else [] end end |
#showname(title = nil) ⇒ Object
def with_name_context name old_context = @context_names add_name_context name result = yield @context_names = old_context result end
44 45 46 47 48 49 50 |
# File 'lib/card/format/names.rb', line 44 def showname title=nil if title card.cardname.title title, @context_names else @showname ||= card.cardname.to_show(*@context_names) end end |