Class: Japonica::Auction
- Inherits:
-
Object
- Object
- Japonica::Auction
- Defined in:
- lib/japonica/auction.rb
Instance Attribute Summary collapse
-
#current_price ⇒ Object
Returns the value of attribute current_price.
-
#item_name ⇒ Object
Returns the value of attribute item_name.
-
#max_bid ⇒ Object
Returns the value of attribute max_bid.
-
#seller_id ⇒ Object
Returns the value of attribute seller_id.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .fetch_html(url) ⇒ Object
- .load_mbok(noko, auction) ⇒ Object
-
.load_url(url) ⇒ Object
Load auction from url.
- .load_yahoo(noko, auction) ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#current_price ⇒ Object
Returns the value of attribute current_price.
11 12 13 |
# File 'lib/japonica/auction.rb', line 11 def current_price @current_price end |
#item_name ⇒ Object
Returns the value of attribute item_name.
9 10 11 |
# File 'lib/japonica/auction.rb', line 9 def item_name @item_name end |
#max_bid ⇒ Object
Returns the value of attribute max_bid.
12 13 14 |
# File 'lib/japonica/auction.rb', line 12 def max_bid @max_bid end |
#seller_id ⇒ Object
Returns the value of attribute seller_id.
10 11 12 |
# File 'lib/japonica/auction.rb', line 10 def seller_id @seller_id end |
#url ⇒ Object
Returns the value of attribute url.
8 9 10 |
# File 'lib/japonica/auction.rb', line 8 def url @url end |
Class Method Details
.fetch_html(url) ⇒ Object
40 41 42 43 44 |
# 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) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# 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_url(url) ⇒ Object
Load auction from url
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# 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 |
.load_yahoo(noko, auction) ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# 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 |
Instance Method Details
#is_mbok? ⇒ Boolean
14 15 16 |
# File 'lib/japonica/auction.rb', line 14 def is_mbok? url =~ /mbok\.jp/i end |
#is_yahoo? ⇒ Boolean
18 19 20 |
# File 'lib/japonica/auction.rb', line 18 def is_yahoo? url =~ /yahoo\.co\.jp/i end |