Class: TCGPlayerSDK::Pokemon

Inherits:
Object
  • Object
show all
Defined in:
lib/tcg-player-sdk/pokemon.rb

Overview

Helpers for pokemon-centric tasks

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_tcg) ⇒ Pokemon

Returns a new instance of Pokemon.



5
6
7
8
# File 'lib/tcg-player-sdk/pokemon.rb', line 5

def initialize(_tcg)
  self.tcg = _tcg
  @category = nil
end

Instance Attribute Details

#tcgObject

Returns the value of attribute tcg.



3
4
5
# File 'lib/tcg-player-sdk/pokemon.rb', line 3

def tcg
  @tcg
end

Instance Method Details

#categoryObject



10
11
12
# File 'lib/tcg-player-sdk/pokemon.rb', line 10

def category
  @category ||= tcg.categories(limit: 100).select{|c| c.name =~ /Pokemon/i}.first
end

#categoryIdObject



14
15
16
# File 'lib/tcg-player-sdk/pokemon.rb', line 14

def categoryId
  category.categoryId
end

#manifestObject



18
19
20
# File 'lib/tcg-player-sdk/pokemon.rb', line 18

def manifest
  @manifest ||= tcg.category_search_manifest(categoryId)
end

#set(set_name) ⇒ Object

Returns the TCGPlayerSDK filter item corresponding to the input set

pokemon.set('Base Set')
[
    [0] TCGPlayerSDK::ResponseStruct {
         :text => "Base Set",
        :value => "Base Set"
    }
]


45
46
47
# File 'lib/tcg-player-sdk/pokemon.rb', line 45

def set(set_name)
  sets.items.select{|i| i.text == set_name}
end

#setsObject

Returns the TCGPlaeryAPI filter corresponding to Sets



24
25
26
# File 'lib/tcg-player-sdk/pokemon.rb', line 24

def sets
  @set_filter ||= @manifest.results.first.filters.select{|f| f.name == 'SetName'}.first
end

#sortingArray<TCGPlayerSDK::ResponseStruct>

the available ways to sort search data. Set :sort in your search parameters to one of the returned :value

Returns:



31
32
33
# File 'lib/tcg-player-sdk/pokemon.rb', line 31

def sorting
  @sorting ||= @manifest.results.first.sorting
end