Class: USaidWat::Thing::User
- Inherits:
-
Object
- Object
- USaidWat::Thing::User
show all
- Defined in:
- lib/usaidwat/thing.rb
Instance Method Summary
collapse
Constructor Details
#initialize(username, user_data, comment_data, post_data) ⇒ User
Returns a new instance of User.
18
19
20
21
22
23
|
# File 'lib/usaidwat/thing.rb', line 18
def initialize(username, user_data, , post_data)
@username = username
@user_data = user_data
@comment_data =
@post_data = post_data
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args, &block) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/usaidwat/thing.rb', line 39
def method_missing(symbol, *args, &block)
if symbol.to_s =~ /_data$/
begin
res = instance_variable_get("@#{symbol}")
raise USaidWat::Client::NoSuchUserError, @username if res == :no_such_user
raise USaidWat::Client::ReachabilityError if res == :server_error
res['data']
rescue NameError
super
end
else
super
end
end
|
Instance Method Details
31
32
33
|
# File 'lib/usaidwat/thing.rb', line 31
def (n)
['children'].map { |d| Comment.new(d) }
end
|
#posts ⇒ Object
35
36
37
|
# File 'lib/usaidwat/thing.rb', line 35
def posts
post_data['children'].map { |d| Submission.new(d) }
end
|