Module: Card::Set::All::Fetch::ClassMethods

Defined in:
card/tmpsets/set/mod002-core/all/fetch.rb

Overview

and “virtual” card construction

Instance Method Summary collapse

Instance Method Details

#[](*mark) ⇒ Card

fetch only real (no virtual) cards

Parameters:

  • mark
    • see #fetch

Returns:



41
42
43
# File 'card/tmpsets/set/mod002-core/all/fetch.rb', line 41

def [] *mark
  fetch(*mark, skip_virtual: true)
end

#fetch(*args) ⇒ Card

Look for cards in * cache * database * virtual cards

Parameters:

  • args (Integer, String, Card::Name, Symbol, Array)

    one or more of the three unique identifiers 1. a numeric id (Integer) 2. a name/key (String or Card::Name) 3. a codename (Symbol) If you pass more then one mark or an array of marks they get joined with a ‘+’. The final argument can be a hash to set the following options :skip_virtual Real cards only :skip_modules Don’t load Set modules :look_in_trash Return trashed card objects :local_only Use only local cache for lookup and storing new: { opts for Card#new } Return a new card when not found

Returns:



31
32
33
34
35
# File 'card/tmpsets/set/mod002-core/all/fetch.rb', line 31

def fetch *args
  Card::Fetch.new(*args)&.retrieve_or_new
rescue ActiveModel::RangeError => _e
  return Card.new name: "card id out of range: #{f.mark}"
end

#fetch_from_cast(cast) ⇒ Card

Returns:



56
57
58
59
# File 'card/tmpsets/set/mod002-core/all/fetch.rb', line 56

def fetch_from_cast cast
  fetch_args = cast[:id] ? [cast[:id].to_i] : [cast[:name], { new: cast }]
  fetch *fetch_args
end

#fetch_id(*mark_parts) ⇒ Integer

Parameters:

  • mark_parts
    • see #fetch

Returns:

  • (Integer)


76
77
78
79
# File 'card/tmpsets/set/mod002-core/all/fetch.rb', line 76

def fetch_id *mark_parts
  mark = Card::Fetch.new(*mark_parts)&.mark
  mark.is_a?(Integer) ? mark : quick_fetch(mark.to_s)&.id
end

#fetch_name(*mark) ⇒ Card::Name

Parameters:

  • mark
    • see #fetch

Returns:



83
84
85
86
87
88
89
90
91
92
93
# File 'card/tmpsets/set/mod002-core/all/fetch.rb', line 83

def fetch_name *mark
  if (card = quick_fetch(*mark))
    card.name
  elsif block_given?
    yield.to_name
  end
rescue ActiveModel::RangeError => _e
  block_given? ? yield.to_name : nil
rescue Card::Error::CodenameNotFound => e
  block_given? ? yield.to_name : raise(e)
end

#fetch_type_id(mark) ⇒ Integer

Parameters:

  • mark
    • see #fetch

Returns:

  • (Integer)


97
98
99
# File 'card/tmpsets/set/mod002-core/all/fetch.rb', line 97

def fetch_type_id mark
  quick_fetch(mark)&.type_id
end

#id(cardish) ⇒ Object


ATTRIBUTE FETCHING The following methods optimize fetching of specific attributes



65
66
67
68
69
70
71
72
# File 'card/tmpsets/set/mod002-core/all/fetch.rb', line 65

def id cardish
  case cardish
  when Integer then cardish
  when Card then cardish.id
  when Symbol then Card::Codename.id cardish
  else fetch_id cardish
  end
end

#quick_fetch(*mark) ⇒ Card

fetch real cards without set modules loaded. Should only be used for simple attributes

Examples:

quick_fetch "A", :self, :structure

Parameters:

  • mark
    • see #fetch

Returns:



51
52
53
# File 'card/tmpsets/set/mod002-core/all/fetch.rb', line 51

def quick_fetch *mark
  fetch(*mark, skip_virtual: true, skip_modules: true)
end