Class: MTG

Inherits:
Object
  • Object
show all
Defined in:
lib/mtg_card_finder/mtg.rb

Constant Summary collapse

ATTRIBUTES =
[
    "Card:",
    "Set:",
    "Market Value:",
    "Rise/Fall amount:",
    "Image URL:"
]
@@modern_up =
[]
@@modern_down =
[]
@@standard_up =
[]
@@standard_down =
[]
@@temp_array =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ MTG

new instance will be created with already assigned values to MTG attrs



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

def initialize(attributes)
  attributes.each {|key, value| self.send("#{key}=", value)}
end

Instance Attribute Details

#cardObject

Returns the value of attribute card.



2
3
4
# File 'lib/mtg_card_finder/mtg.rb', line 2

def card
  @card
end

#imageObject

Returns the value of attribute image.



2
3
4
# File 'lib/mtg_card_finder/mtg.rb', line 2

def image
  @image
end

#market_priceObject

Returns the value of attribute market_price.



2
3
4
# File 'lib/mtg_card_finder/mtg.rb', line 2

def market_price
  @market_price
end

#price_fluctuateObject

Returns the value of attribute price_fluctuate.



2
3
4
# File 'lib/mtg_card_finder/mtg.rb', line 2

def price_fluctuate
  @price_fluctuate
end

#setsObject

Returns the value of attribute sets.



2
3
4
# File 'lib/mtg_card_finder/mtg.rb', line 2

def sets
  @sets
end

Class Method Details

.all(format) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/mtg_card_finder/mtg.rb', line 55

def self.all(format)
  #iterate through each instance that was appended into class variable during initialization
  format.each_with_index do |card, number|
    puts ""
    puts "|- #{number + 1} -|".fg COLORS[4]
    puts ""
      #line below helps resolve glitch that allows 'ghost/invalid' cards to be selected from Parser.purchase
      if number < Parser.table_length
      #iterate through each instance method that was defined for the stored instance variable
      card.instance_variables.each_with_index do |value, index|
        #returns the value of the instance method applied to the instance
        #with an index value of the first/last, key/value pairs ordered in Parser.scrape_cards
        #associates a named definition of the values by titling it from constant ATTRIBUTES
        if index < 4
          puts "#{ATTRIBUTES[index].fg COLORS[2]} #{card.instance_variable_get(value)}"
        end
      end
    end
    puts ""
    print "                                                 ".bg COLORS[7]
  end
end

.create_modern_down(attributes) ⇒ Object



43
44
45
# File 'lib/mtg_card_finder/mtg.rb', line 43

def self.create_modern_down(attributes)
  cards = MTG.new(attributes).tap {|card| card.save_modern_down}
end

.create_modern_up(attributes) ⇒ Object



38
39
40
41
# File 'lib/mtg_card_finder/mtg.rb', line 38

def self.create_modern_up(attributes)
  #allows cards instance to auto return thanks to tap implementation
  cards = MTG.new(attributes).tap {|card| card.save_modern_up}
end

.create_standard_down(attributes) ⇒ Object



51
52
53
# File 'lib/mtg_card_finder/mtg.rb', line 51

def self.create_standard_down(attributes)
  cards = MTG.new(attributes).tap {|card| card.save_standard_down}
end

.create_standard_up(attributes) ⇒ Object



47
48
49
# File 'lib/mtg_card_finder/mtg.rb', line 47

def self.create_standard_up(attributes)
  cards = MTG.new(attributes).tap {|card| card.save_standard_up}
end

.modern_downObject



106
107
108
# File 'lib/mtg_card_finder/mtg.rb', line 106

def self.modern_down
  @@modern_down
end

.modern_upObject



102
103
104
# File 'lib/mtg_card_finder/mtg.rb', line 102

def self.modern_up
  @@modern_up
end

.search_modern_downObject



90
91
92
# File 'lib/mtg_card_finder/mtg.rb', line 90

def self.search_modern_down
  self.all(@@modern_down)
end

.search_modern_upObject



86
87
88
# File 'lib/mtg_card_finder/mtg.rb', line 86

def self.search_modern_up
  self.all(@@modern_up)
end

.search_standard_downObject



98
99
100
# File 'lib/mtg_card_finder/mtg.rb', line 98

def self.search_standard_down
  self.all(@@standard_down)
end

.search_standard_upObject



94
95
96
# File 'lib/mtg_card_finder/mtg.rb', line 94

def self.search_standard_up
  self.all(@@standard_up)
end

.standard_downObject



114
115
116
# File 'lib/mtg_card_finder/mtg.rb', line 114

def self.standard_down
  @@standard_down
end

.standard_upObject



110
111
112
# File 'lib/mtg_card_finder/mtg.rb', line 110

def self.standard_up
  @@standard_up
end

.store_temp_array(array) ⇒ Object

hack that resolves glitch that would display duplicate recursions in the selected cards to show by user request in CLI.set_input



80
81
82
83
84
# File 'lib/mtg_card_finder/mtg.rb', line 80

def self.store_temp_array(array)
  @@temp_array = array
  self.all(@@temp_array)
  @@temp_array.clear
end

Instance Method Details

#save_modern_downObject



26
27
28
# File 'lib/mtg_card_finder/mtg.rb', line 26

def save_modern_down
  @@modern_down << self
end

#save_modern_upObject



22
23
24
# File 'lib/mtg_card_finder/mtg.rb', line 22

def save_modern_up
  @@modern_up << self
end

#save_standard_downObject



34
35
36
# File 'lib/mtg_card_finder/mtg.rb', line 34

def save_standard_down
  @@standard_down << self
end

#save_standard_upObject



30
31
32
# File 'lib/mtg_card_finder/mtg.rb', line 30

def save_standard_up
  @@standard_up << self
end