Class: Elekk::Wowhead::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/elekk/wowhead.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, name, kind, icon = nil, quality = nil) ⇒ Result

Returns a new instance of Result.



19
20
21
22
23
24
25
# File 'lib/elekk/wowhead.rb', line 19

def initialize(id, name, kind, icon=nil, quality=nil)
  @id = id
  @name = name
  @kind = kind
  @icon = icon
  @quality = Quality[quality] if quality
end

Instance Attribute Details

#iconObject (readonly)

Returns the value of attribute icon.



17
18
19
# File 'lib/elekk/wowhead.rb', line 17

def icon
  @icon
end

#idObject (readonly)

Returns the value of attribute id.



17
18
19
# File 'lib/elekk/wowhead.rb', line 17

def id
  @id
end

#kindObject (readonly)

Returns the value of attribute kind.



17
18
19
# File 'lib/elekk/wowhead.rb', line 17

def kind
  @kind
end

#nameObject (readonly)

Returns the value of attribute name.



17
18
19
# File 'lib/elekk/wowhead.rb', line 17

def name
  @name
end

#qualityObject (readonly)

Returns the value of attribute quality.



17
18
19
# File 'lib/elekk/wowhead.rb', line 17

def quality
  @quality
end

Class Method Details

.from_html(mkp) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/elekk/wowhead.rb', line 44

def self.from_html(mkp)
  html = Nokogiri.HTML(mkp)
  link = html.at_css('a')
  return unless link
  if link['href'] =~ /wowhead.com\/(\w+)\=(\d+)/
    id = $2
    kind = Kind.find(/^#{$1}$/i)
    quality = $1.to_i if kind == Kind::Item and link['class'] =~ /q(\d)/
  end
  name = link.content
  Result.new id, name, kind, nil, quality
end

Instance Method Details

#icon_url(size = :medium) ⇒ Object

:small, :medium, or :large



40
41
42
# File 'lib/elekk/wowhead.rb', line 40

def icon_url(size=:medium) # :small, :medium, or :large
  "http://static.wowhead.com/images/wow/icons/#{size}/#{icon.gsub(/'/,'-')}.jpg" if icon
end

#to_htmlObject



31
32
33
34
# File 'lib/elekk/wowhead.rb', line 31

def to_html
  q = (@kind == Kind::Item) ? " class='q#{@quality.to_i}'" : ''
  "<a href='#{url}'#{q}>#{@name}</a>"
end

#to_sObject



27
28
29
# File 'lib/elekk/wowhead.rb', line 27

def to_s
  @name
end

#urlObject



36
37
38
# File 'lib/elekk/wowhead.rb', line 36

def url
  "http://www.wowhead.com/#{@kind.to_s.downcase}=#{@id}"
end