Class: Snooby::User
- Inherits:
-
Object
- Object
- Snooby::User
- Defined in:
- lib/snooby/user.rb
Instance Method Summary collapse
- #disliked(count = 25) ⇒ Object
- #friend(un = '') ⇒ Object
- #hidden(count = 25) ⇒ Object
-
#initialize(name) ⇒ User
constructor
A new instance of User.
- #karma_breakdown ⇒ Object
- #liked(count = 25) ⇒ Object
-
#trophies ⇒ Object
Returns an array of arrays containing the user’s trophy information in the form of [name, description], the latter containing the empty string if inapplicable.
- #unfriend ⇒ Object
Methods included from About
Methods included from Posts
Methods included from Comments
Methods included from Compose
Constructor Details
#initialize(name) ⇒ User
6 7 8 9 |
# File 'lib/snooby/user.rb', line 6 def initialize(name) @name = name @kind = 'user' end |
Instance Method Details
#disliked(count = 25) ⇒ Object
31 32 33 |
# File 'lib/snooby/user.rb', line 31 def disliked(count = 25) Snooby.build Post, :disliked, @name, count end |
#friend(un = '') ⇒ Object
39 40 41 42 |
# File 'lib/snooby/user.rb', line 39 def friend(un = '') data = {:name => @name, :type => 'friend', :container => Snooby.active.id} Snooby.request Paths[:"#{un}friend"], data end |
#hidden(count = 25) ⇒ Object
35 36 37 |
# File 'lib/snooby/user.rb', line 35 def hidden(count = 25) Snooby.build Post, :hidden, @name, count end |
#karma_breakdown ⇒ Object
21 22 23 24 25 |
# File 'lib/snooby/user.rb', line 21 def karma_breakdown html = Snooby.request(Paths[:user] % @name + '?limit=1', 'html') rx = /h>(.+?)<.+?(\d+).+?(\d+)/ Hash[html.split('y>')[2].scan(rx).map { |r| [r.shift, r.map(&:to_i)] }] end |
#liked(count = 25) ⇒ Object
27 28 29 |
# File 'lib/snooby/user.rb', line 27 def liked(count = 25) Snooby.build Post, :liked, @name, count end |
#trophies ⇒ Object
Returns an array of arrays containing the user’s trophy information in the form of [name, description], the latter containing the empty string if inapplicable.
14 15 16 17 18 19 |
# File 'lib/snooby/user.rb', line 14 def trophies # Only interested in trophies; request the minimum amount of content. html = Snooby.request(Paths[:user] % @name + '?limit=1', 'html') # Entry-level black magic. html.scan /"trophy-name">(.+?)<.+?"\s?>([^<]*)</ end |
#unfriend ⇒ Object
44 45 46 |
# File 'lib/snooby/user.rb', line 44 def unfriend friend 'un' end |