Class: JekyllMTG::LinkCard

Inherits:
Liquid::Tag
  • Object
show all
Includes:
Utils
Defined in:
lib/jekyll_mtg.rb

Overview

Links cards

Constant Summary

Constants included from Utils

Utils::DEFAULT_REQUEST_FORMAT, Utils::SCRYFALL_BASE_URI, Utils::SCRYFALL_FUZZY_PATH

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#fetch_card, #parse_card_info

Constructor Details

#initialize(tag_name, card_info, tokens) ⇒ LinkCard

Returns a new instance of LinkCard.



12
13
14
15
16
# File 'lib/jekyll_mtg.rb', line 12

def initialize(tag_name, card_info, tokens)
  super

  @card_info = card_info
end

Instance Attribute Details

#card_infoObject (readonly)

Returns the value of attribute card_info.



18
19
20
# File 'lib/jekyll_mtg.rb', line 18

def card_info
  @card_info
end

Instance Method Details

#render(_context) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/jekyll_mtg.rb', line 20

def render(_context)
  parsed_card_info = parse_card_info(card_info)
  response = fetch_card(parsed_card_info)

  text = parsed_card_info[:contents] || parsed_card_info[:card_name]
  if response['scryfall_uri']
    "<a href='#{response["scryfall_uri"]}'>#{text}</a>"
  else
    text
  end
end