Class: Woot
- Inherits:
-
Object
- Object
- Woot
- Defined in:
- lib/woot.rb,
lib/woot.rb
Constant Summary collapse
- DOMAIN =
'woot.com'
- SELLOUT_DOMAIN =
'shopping.yahoo.com'
- WOOT_OFF =
'woot-off'
- TWITTER_IDS =
{ 'kids' => 66527200, 'shirt' => 7696162, 'sellout' => 15458304, 'wine' => 1647621, 'www' => 734493, WOOT_OFF => 20557892 }
- SUBDOMAINS =
TWITTER_IDS.keys - [WOOT_OFF]
Instance Attribute Summary collapse
-
#subdomain ⇒ Object
readonly
Returns the value of attribute subdomain.
Class Method Summary collapse
- .attribute(name, selector, result = nil, &block) ⇒ Object
- .attributes ⇒ Object
- .stop ⇒ Object
- .stream(twitter_username, twitter_password) ⇒ Object
Instance Method Summary collapse
- #document ⇒ Object
- #html ⇒ Object
-
#initialize(subdomain = 'www') ⇒ Woot
constructor
A new instance of Woot.
Constructor Details
#initialize(subdomain = 'www') ⇒ Woot
Returns a new instance of Woot.
23 24 25 |
# File 'lib/woot.rb', line 23 def initialize(subdomain = 'www') @subdomain = subdomain.to_s end |
Instance Attribute Details
#subdomain ⇒ Object (readonly)
Returns the value of attribute subdomain.
21 22 23 |
# File 'lib/woot.rb', line 21 def subdomain @subdomain end |
Class Method Details
.attribute(name, selector, result = nil, &block) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/woot.rb', line 35 def self.attribute(name, selector, result = nil, &block) attributes << name unless attributes.include?(name) instance_variable_name = "@#{name}" define_method name do instance_variable_set(instance_variable_name, parse(selector, block_given? ? block : result)) unless instance_variable_defined?(instance_variable_name) instance_variable_get(instance_variable_name) end end |
.attributes ⇒ Object
44 45 46 |
# File 'lib/woot.rb', line 44 def self.attributes @attributes ||= [] end |
.stop ⇒ Object
55 56 57 |
# File 'lib/woot.rb', line 55 def self.stop TweetStream::Client.stop end |
.stream(twitter_username, twitter_password) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/woot.rb', line 48 def self.stream(twitter_username, twitter_password) TweetStream::Client.new(twitter_username, twitter_password).follow(*TWITTER_IDS.values) do |status| subdomain = subdomain_from_twitter_status(status) yield new(subdomain) unless subdomain.nil? end end |
Instance Method Details
#document ⇒ Object
27 28 29 |
# File 'lib/woot.rb', line 27 def document @document ||= Nokogiri::HTML(html) end |
#html ⇒ Object
31 32 33 |
# File 'lib/woot.rb', line 31 def html @html ||= Net::HTTP.get(URI.parse(scrape_url)) end |