Class: Wowget::Spell
- Inherits:
-
Object
- Object
- Wowget::Spell
- Defined in:
- lib/wowget/spell.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
Returns the value of attribute error.
-
#id ⇒ Object
Returns the value of attribute id.
-
#item_id ⇒ Object
Returns the value of attribute item_id.
-
#item_quantity_max ⇒ Object
Returns the value of attribute item_quantity_max.
-
#item_quantity_min ⇒ Object
Returns the value of attribute item_quantity_min.
-
#name ⇒ Object
Returns the value of attribute name.
-
#profession ⇒ Object
Returns the value of attribute profession.
-
#profession_id ⇒ Object
Returns the value of attribute profession_id.
-
#reagents ⇒ Object
Returns the value of attribute reagents.
-
#skill ⇒ Object
Returns the value of attribute skill.
-
#skillup ⇒ Object
Returns the value of attribute skillup.
-
#source_id ⇒ Object
Returns the value of attribute source_id.
Instance Method Summary collapse
-
#initialize(spell_id) ⇒ Spell
constructor
A new instance of Spell.
- #source ⇒ Object
Constructor Details
#initialize(spell_id) ⇒ Spell
Returns a new instance of Spell.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/wowget/spell.rb', line 20 def initialize(spell_id) begin url = open("http://www.wowhead.com/spell=#{spell_id}") rescue not_found = true end spell_xml = Nokogiri::XML(url) unless not_found if not_found || spell_xml.css('div#inputbox-error').length == 1 self.error = {:error => "not found"} else self.name = spell_xml.css('div.text h1').inner_text.strip.to_s # retrieve recipe data recipe = spell_xml.inner_text.match(/^new Listview\(\{template: 'spell', id: 'recipes', .*, data: (\[\{.*\}\])\}\);$/) unless recipe.nil? recipe_json = (JSON recipe[1])[0] unless recipe_json["creates"].nil? # item produced and quantity self.item_id = recipe_json["creates"][0] self.item_quantity_min = recipe_json["creates"][1] self.item_quantity_max = recipe_json["creates"][2] # profession unless recipe_json["skill"].nil? profession = wowhead_profession(recipe_json["skill"][0]) self.profession = profession[:name] self.profession_id = profession[:id] self.skill = recipe_json["learnedat"] self.skillup = recipe_json["nskillup"] self.source_id = recipe_json["source"][0] end # reagents self.reagents = [] recipe_json["reagents"].each do |reagent| item_id = reagent[0] quantity = self.profession_id.nil? ? reagent[1] + 1 : reagent[1] self.reagents.push({:item => Wowget::Item.new(item_id), :quantity => quantity}) end end end end end |
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
18 19 20 |
# File 'lib/wowget/spell.rb', line 18 def error @error end |
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/wowget/spell.rb', line 7 def id @id end |
#item_id ⇒ Object
Returns the value of attribute item_id.
9 10 11 |
# File 'lib/wowget/spell.rb', line 9 def item_id @item_id end |
#item_quantity_max ⇒ Object
Returns the value of attribute item_quantity_max.
11 12 13 |
# File 'lib/wowget/spell.rb', line 11 def item_quantity_max @item_quantity_max end |
#item_quantity_min ⇒ Object
Returns the value of attribute item_quantity_min.
10 11 12 |
# File 'lib/wowget/spell.rb', line 10 def item_quantity_min @item_quantity_min end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/wowget/spell.rb', line 8 def name @name end |
#profession ⇒ Object
Returns the value of attribute profession.
13 14 15 |
# File 'lib/wowget/spell.rb', line 13 def profession @profession end |
#profession_id ⇒ Object
Returns the value of attribute profession_id.
14 15 16 |
# File 'lib/wowget/spell.rb', line 14 def profession_id @profession_id end |
#reagents ⇒ Object
Returns the value of attribute reagents.
12 13 14 |
# File 'lib/wowget/spell.rb', line 12 def reagents @reagents end |
#skill ⇒ Object
Returns the value of attribute skill.
15 16 17 |
# File 'lib/wowget/spell.rb', line 15 def skill @skill end |
#skillup ⇒ Object
Returns the value of attribute skillup.
16 17 18 |
# File 'lib/wowget/spell.rb', line 16 def skillup @skillup end |
#source_id ⇒ Object
Returns the value of attribute source_id.
17 18 19 |
# File 'lib/wowget/spell.rb', line 17 def source_id @source_id end |
Instance Method Details
#source ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/wowget/spell.rb', line 68 def source case self.source_id when 1 then "Crafted" when 2 then "Drop" when 3 then "PvP" when 4 then "Quest" when 5 then "Vendor" when 6 then "Trainer" when 7 then "Discovery" when 8 then "Redemption" when 9 then "Talent" when 10 then "Starter" when 11 then "Event" when 12 then "Achievement" end end |