class Japonica::Auction
Attributes
current_price[RW]
item_name[RW]
max_bid[RW]
seller_id[RW]
url[RW]
Public Class Methods
load_url(url)
click to toggle source
Load auction from url
# File lib/japonica/auction.rb, line 23 def self.load_url(url) auction = Auction.new auction.url = url html = fetch_html url if auction.is_mbok? load_mbok html, auction elsif auction.is_yahoo? load_yahoo html, auction else nil end end
Private Class Methods
fetch_html(url)
click to toggle source
# File lib/japonica/auction.rb, line 40 def self.fetch_html(url) response = HTTParty.get url html = response.body Nokogiri::HTML html end
load_mbok(noko, auction)
click to toggle source
# File lib/japonica/auction.rb, line 46 def self.load_mbok(noko, auction) item_name = noko.at_css 'h1.title[itemprop=name]' seller_id = noko.at_css 'p.owner-name a' current_price = noko.at_css 'span[itemprop=Price]' auction.item_name = item_name.text unless item_name.nil? auction.seller_id = seller_id.text unless seller_id.nil? auction.current_price = current_price.text unless current_price.nil? auction end
load_yahoo(noko, auction)
click to toggle source
# File lib/japonica/auction.rb, line 57 def self.load_yahoo(noko, auction) item_name = noko.at_css "h1[property='auction:Title']" seller_id = noko.at_css "b[property='auction:SellerID']" current_price = noko.at_css "p[property='auction:Price']" auction.item_name = item_name.text unless item_name.nil? auction.seller_id = seller_id.text unless seller_id.nil? auction.current_price = current_price.text unless current_price.nil? auction end
Public Instance Methods
is_mbok?()
click to toggle source
# File lib/japonica/auction.rb, line 14 def is_mbok? url =~ /mbok\.jp/i end
is_yahoo?()
click to toggle source
# File lib/japonica/auction.rb, line 18 def is_yahoo? url =~ /yahoo\.co\.jp/i end