Class: Elekk::Wowhead::Result
- Inherits:
-
Object
- Object
- Elekk::Wowhead::Result
- Defined in:
- lib/elekk/wowhead.rb
Instance Attribute Summary collapse
-
#icon ⇒ Object
readonly
Returns the value of attribute icon.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#quality ⇒ Object
readonly
Returns the value of attribute quality.
Class Method Summary collapse
Instance Method Summary collapse
-
#icon_url(size = :medium) ⇒ Object
:small, :medium, or :large.
-
#initialize(id, name, kind, icon = nil, quality = nil) ⇒ Result
constructor
A new instance of Result.
- #to_html ⇒ Object
- #to_s ⇒ Object
- #url ⇒ Object
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
#icon ⇒ Object (readonly)
Returns the value of attribute icon.
17 18 19 |
# File 'lib/elekk/wowhead.rb', line 17 def icon @icon end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
17 18 19 |
# File 'lib/elekk/wowhead.rb', line 17 def id @id end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
17 18 19 |
# File 'lib/elekk/wowhead.rb', line 17 def kind @kind end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
17 18 19 |
# File 'lib/elekk/wowhead.rb', line 17 def name @name end |
#quality ⇒ Object (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_html ⇒ Object
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_s ⇒ Object
27 28 29 |
# File 'lib/elekk/wowhead.rb', line 27 def to_s @name end |
#url ⇒ Object
36 37 38 |
# File 'lib/elekk/wowhead.rb', line 36 def url "http://www.wowhead.com/#{@kind.to_s.downcase}=#{@id}" end |