Class: Goodwill::Auction
- Inherits:
-
Object
- Object
- Goodwill::Auction
- Defined in:
- lib/goodwill/auction.rb
Overview
A ShopGoodwill Auction
Direct Known Subclasses
Constant Summary
Constants included from URLPaths
URLPaths::BID_URL, URLPaths::ITEM_SEARCH_URL, URLPaths::LOGIN_URL, URLPaths::OPEN_ORDERS_URL, URLPaths::SEARCH_URL, URLPaths::SHIPPING_URL
Constants included from CSSPaths
CSSPaths::BIDS_PATH, CSSPaths::BIN_END_TIME_PATH, CSSPaths::BUY_IT_NOW_PATH, CSSPaths::CURRENT_PRICE_PATH, CSSPaths::END_TIME_PATH, CSSPaths::IN_PROGRESS_ROWS, CSSPaths::ITEMID_PATH, CSSPaths::ITEMS_COUNT_PATH, CSSPaths::ITEM_TITLE_PATH, CSSPaths::NO_ITEMS_FOUND_PATH, CSSPaths::SEARCH_ROWS, CSSPaths::SELLER_ID_LINK, CSSPaths::SELLER_PATH, CSSPaths::SHIPPING_PATH
Instance Attribute Summary collapse
-
#bids ⇒ Object
readonly
Returns the value of attribute bids.
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#end ⇒ Object
readonly
Returns the value of attribute end.
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#item ⇒ Object
readonly
Returns the value of attribute item.
-
#item_page ⇒ Object
readonly
Returns the value of attribute item_page.
-
#itemid ⇒ Object
readonly
Returns the value of attribute itemid.
-
#seller ⇒ Object
readonly
Returns the value of attribute seller.
-
#shipping ⇒ Object
readonly
Returns the value of attribute shipping.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(itemid, zipcode = '97222', state = 'OR', country = 'US') ⇒ Auction
constructor
A new instance of Auction.
- #to_hash ⇒ Object
Methods included from Mechanize
logged_in?, login, #mechanize, mechanize
Constructor Details
#initialize(itemid, zipcode = '97222', state = 'OR', country = 'US') ⇒ Auction
Returns a new instance of Auction.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/goodwill/auction.rb', line 20 def initialize(itemid, zipcode = '97222', state = 'OR', country = 'US') @itemid = itemid @zipcode = zipcode @state = state @country = country @href = ITEM_SEARCH_URL + itemid.to_s @item_page = mechanize.get(@href) @type = parse_type @bids = item_page.search(BIDS_PATH).text[/\d+/].to_i @current = item_page.search(CURRENT_PRICE_PATH).text.tr('$', '').to_f @end = parse_end_time @item = item_page.search(ITEM_TITLE_PATH).text @seller = item_page.search(SELLER_PATH).text @bidding = false @shipping = calculate_shipping(@itemid, @zipcode, @country) end |
Instance Attribute Details
#bids ⇒ Object (readonly)
Returns the value of attribute bids.
18 19 20 |
# File 'lib/goodwill/auction.rb', line 18 def bids @bids end |
#current ⇒ Object (readonly)
Returns the value of attribute current.
18 19 20 |
# File 'lib/goodwill/auction.rb', line 18 def current @current end |
#end ⇒ Object (readonly)
Returns the value of attribute end.
18 19 20 |
# File 'lib/goodwill/auction.rb', line 18 def end @end end |
#href ⇒ Object (readonly)
Returns the value of attribute href.
18 19 20 |
# File 'lib/goodwill/auction.rb', line 18 def href @href end |
#item ⇒ Object (readonly)
Returns the value of attribute item.
18 19 20 |
# File 'lib/goodwill/auction.rb', line 18 def item @item end |
#item_page ⇒ Object (readonly)
Returns the value of attribute item_page.
18 19 20 |
# File 'lib/goodwill/auction.rb', line 18 def item_page @item_page end |
#itemid ⇒ Object (readonly)
Returns the value of attribute itemid.
18 19 20 |
# File 'lib/goodwill/auction.rb', line 18 def itemid @itemid end |
#seller ⇒ Object (readonly)
Returns the value of attribute seller.
18 19 20 |
# File 'lib/goodwill/auction.rb', line 18 def seller @seller end |
#shipping ⇒ Object (readonly)
Returns the value of attribute shipping.
18 19 20 |
# File 'lib/goodwill/auction.rb', line 18 def shipping @shipping end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
18 19 20 |
# File 'lib/goodwill/auction.rb', line 18 def type @type end |
Instance Method Details
#==(other) ⇒ Object
39 40 41 |
# File 'lib/goodwill/auction.rb', line 39 def ==(other) itemid == other.itemid end |
#to_hash ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/goodwill/auction.rb', line 43 def to_hash hash = {} instance_variables.each do |var| next if var == :@item_page hash[var.to_s.delete('@')] = if var == :@end instance_variable_get(var).to_s else instance_variable_get(var) end end hash end |