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_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.



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

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



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/wowr/item.rb', line 37

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
	
	# http://www.wowarmory.com/images/icons/64x64/blahblah.jpg
	return base + @@icon_url_base + @@icon_sizes[size][0] + '/' + @icon_base + '.' + @@icon_sizes[size][1]
end