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
- #initialize_context_names ⇒ Object
- #showname(title = nil) ⇒ Object
- #with_name_context(name) ⇒ Object
Instance Method Details
#add_name_context(name = nil) ⇒ Object
24 25 26 27 28 |
# File 'lib/card/format/names.rb', line 24 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
19 20 21 22 |
# File 'lib/card/format/names.rb', line 19 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
14 15 16 17 |
# File 'lib/card/format/names.rb', line 14 def context_names_minus_irrelevants part_keys = @card.cardname.part_names.map(&:key) @context_names.reject { |n| !part_keys.include? n.key } end |
#initialize_context_names ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/card/format/names.rb', line 4 def initialize_context_names if @context_names context_names_minus_irrelevants elsif params[:slot] context_names_from_params else [] end end |
#showname(title = nil) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/card/format/names.rb', line 38 def showname title=nil if title title.to_name.to_absolute_name(card.cardname).to_show(*@context_names) else @showname ||= card.cardname.to_show(*@context_names) end end |
#with_name_context(name) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/card/format/names.rb', line 30 def with_name_context name old_context = @context_names add_name_context name result = yield @context_names = old_context result end |