Class: Wowr::Classes::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/wowr/item.rb

Overview

Most basic Composed of an ItemInfo and Needs to be consolidated with ItemInfo and other stuff to be a parent class that they extend? TODO: At the moment needs a reference to the API in order to get the base URL for icons TODO: Make extend Icon class

Constant Summary collapse

@@icon_url_base =
'images/icons/'
@@icon_url_base_tw =
'wow-icons/_images/'
@@icon_sizes =
{:large => ['64x64', 'jpg'], :medium => ['43x43', 'png'], :small => ['21x21', 'png']}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(elem, api = nil) ⇒ Item

Returns a new instance of Item.



30
31
32
33
34
35
36
# File 'lib/wowr/item.rb', line 30

def initialize(elem, api = nil)
	@api = api
	
	@id 				= elem[:id].to_i
	@name 			= elem[:name]
	@icon_base 	= elem[:icon]
end

Instance Attribute Details

#icon_baseObject (readonly)

Returns the value of attribute icon_base.



21
22
23
# File 'lib/wowr/item.rb', line 21

def icon_base
  @icon_base
end

#idObject (readonly) Also known as: item_id, to_i

Returns the value of attribute id.



21
22
23
# File 'lib/wowr/item.rb', line 21

def id
  @id
end

#nameObject (readonly) Also known as: to_s

Returns the value of attribute name.



21
22
23
# File 'lib/wowr/item.rb', line 21

def name
  @name
end

Instance Method Details

#icon(size = :medium) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/wowr/item.rb', line 38

def icon(size = :medium)
	if !@@icon_sizes.include?(size)
		raise Wowr::Exceptions::InvalidIconSize.new(@@icon_sizes)
	end
	
	if @api
		base = @api.base_url
	else
		base = 'http://www.wowarmory.com/'
	end

	if @api && @api.locale == "tw"
	  url_base = @@icon_url_base_tw
	else
	  url_base = @@icon_url_base
	end
	
	# http://www.wowarmory.com/images/icons/64x64/blahblah.jpg
	return base + url_base + @@icon_sizes[size][0] + '/' + @icon_base + '.' + @@icon_sizes[size][1]
end