Class: PoeWatch::Item

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

Constant Summary

Constants inherited from Base

Base::INFLECTOR

Instance Method Summary collapse

Methods inherited from Base

__data, __data=, all, count, find, #initialize, type, where

Constructor Details

This class inherits a constructor from PoeWatch::Base

Instance Method Details

#price_for_league(name_or_regexp) ⇒ Object



15
16
17
# File 'lib/item.rb', line 15

def price_for_league(name_or_regexp)
  prices.find { |data| name_or_regexp.is_a?(String) ? data.name.downcase == name_or_regexp.downcase : data.name.match(name_or_regexp) }
end

#price_for_leagues(name_or_regexp) ⇒ Object



10
11
12
13
# File 'lib/item.rb', line 10

def price_for_leagues(name_or_regexp)
  regexp = name_or_regexp.is_a?(String) ? Regexp.new(name_or_regexp, 'i') : name_or_regexp
  prices.select { |data| data.name.match(regexp) }
end

#pricesObject



6
7
8
# File 'lib/item.rb', line 6

def prices
  @prices ||= PoeWatch::Api.request(PoeWatch::Api::ITEM_API, { id: self.id }, true)["leagues"].map { |league_data| PoeWatch::PriceData.new(league_data) }
end