Module: Card::Fetch::Results
- Included in:
- Card::Fetch
- Defined in:
- lib/card/fetch/results.rb
Overview
polishing fetch results
Instance Method Summary collapse
- #assign_name_from_mark ⇒ Object
- #assignable_content(default_content) ⇒ Object
-
#fancy_renew? ⇒ Boolean
contains subcards, etc, that quick_renew can’t handle.
- #finalize_result_card ⇒ Object
- #name_change? ⇒ Boolean
- #new_opts ⇒ Object
- #new_result_card ⇒ Object
- #newish_opts ⇒ Object
- #quick_content ⇒ Object
- #quick_renew ⇒ Object
- #quick_renew? ⇒ Boolean
- #renew ⇒ Object
- #results ⇒ Object
- #supercard_might_change_type? ⇒ Boolean
- #type_change? ⇒ Boolean
- #type_id_from_new_opts ⇒ Object
- #update_supercard ⇒ Object
- #with_new_card ⇒ Object
Instance Method Details
#assign_name_from_mark ⇒ Object
118 119 120 121 122 |
# File 'lib/card/fetch/results.rb', line 118 def assign_name_from_mark return if opts[:local_only] return unless mark&.to_s != card.name card.name = mark.to_s end |
#assignable_content(default_content) ⇒ Object
81 82 83 |
# File 'lib/card/fetch/results.rb', line 81 def assignable_content default_content new_opts[:content] || (@card.db_content.blank? && default_content) end |
#fancy_renew? ⇒ Boolean
contains subcards, etc, that quick_renew can’t handle
75 76 77 78 79 |
# File 'lib/card/fetch/results.rb', line 75 def fancy_renew? test_opts = new_opts.slice :supercard, :name, :type_id, :type, :type_code, :content, :default_content new_opts.keys.size > test_opts.keys.size end |
#finalize_result_card ⇒ Object
10 11 12 13 |
# File 'lib/card/fetch/results.rb', line 10 def finalize_result_card card.include_set_modules unless skip_modules? card end |
#name_change? ⇒ Boolean
90 91 92 93 94 |
# File 'lib/card/fetch/results.rb', line 90 def name_change? return false unless (new_name = new_opts[:name]&.to_name) return false if new_name.relative? && mark.name? && mark.absolute? new_name.to_s != @card.name.to_s end |
#new_opts ⇒ Object
114 115 116 |
# File 'lib/card/fetch/results.rb', line 114 def new_opts @new_opts ||= opts[:new] end |
#new_result_card ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/card/fetch/results.rb', line 15 def new_result_card with_new_card do finalize_result_card # must include_set_modules before checking `card.known?`, # in case, eg, set modules override #virtual? card if new_opts || card.known? end end |
#newish_opts ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/card/fetch/results.rb', line 42 def newish_opts hash = new_opts.clone.reverse_merge name: mark if (content = assignable_content(hash.delete(:default_content))) hash[:content] = content end hash[:type_lookup] = :force if @force_type_lookup hash end |
#quick_content ⇒ Object
85 86 87 88 |
# File 'lib/card/fetch/results.rb', line 85 def quick_content return unless (content = assignable_content(new_opts[:default_content])) @card.content = content end |
#quick_renew ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/card/fetch/results.rb', line 51 def quick_renew return false unless quick_renew? # Rails.logger.info "QUICK renewing: #{mark}, #{new_opts}" update_supercard assign_name_from_mark true end |
#quick_renew? ⇒ Boolean
66 67 68 69 70 71 72 |
# File 'lib/card/fetch/results.rb', line 66 def quick_renew? return true if new_opts.blank? return false if type_change? || name_change? return false if fancy_renew? quick_content true end |
#renew ⇒ Object
35 36 37 38 39 40 |
# File 'lib/card/fetch/results.rb', line 35 def renew return if new_opts.blank? # Rails.logger.info "renewing: #{mark}, #{new_opts}" @card = card.dup @card.newish newish_opts end |
#results ⇒ Object
5 6 7 8 |
# File 'lib/card/fetch/results.rb', line 5 def results return if card.nil? card.new_card? ? new_result_card : finalize_result_card end |
#supercard_might_change_type? ⇒ Boolean
108 109 110 111 112 |
# File 'lib/card/fetch/results.rb', line 108 def supercard_might_change_type? # ...via type_plus_right rule sc = new_opts[:supercard] @force_type_lookup = sc&.new? && (sc.type_id != sc.default_type_id) end |
#type_change? ⇒ Boolean
96 97 98 99 100 101 |
# File 'lib/card/fetch/results.rb', line 96 def type_change? return true if @card.type_id.nil? type_id = type_id_from_new_opts return true if !type_id && supercard_might_change_type? type_id && (type_id != @card.type_id) end |
#type_id_from_new_opts ⇒ Object
103 104 105 106 |
# File 'lib/card/fetch/results.rb', line 103 def type_id_from_new_opts type_id = new_opts[:type_id] || new_opts[:type] || new_opts[:type_code]&.to_sym type_id.is_a?(Symbol) ? Codename.id(type_id) : type_id end |
#update_supercard ⇒ Object
60 61 62 63 64 |
# File 'lib/card/fetch/results.rb', line 60 def update_supercard return unless (sc = new_opts[:supercard]) @card.supercard = sc @card.update_superleft @card.name end |
#with_new_card ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/card/fetch/results.rb', line 24 def with_new_card if new_opts quick_renew || renew elsif opts[:skip_virtual] return nil else assign_name_from_mark end yield end |