Class: FakeFriends::FakeFriend
- Inherits:
-
Object
- Object
- FakeFriends::FakeFriend
- Defined in:
- lib/fake_friends.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#posts ⇒ Object
readonly
Returns the value of attribute posts.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
-
.find_by(options) ⇒ Object
FakeFriend.find_by(options).
-
.gather(n) ⇒ Object
Friend.gather(n) returns an array of n user objects.
Instance Method Summary collapse
-
#avatar_url(size) ⇒ Object
avatar_url(size) returns the user’s uiFaces url in the closest available size.
-
#initialize(username) ⇒ FakeFriend
constructor
FakeFriend.new(username).
Constructor Details
#initialize(username) ⇒ FakeFriend
FakeFriend.new(username)
username <string>
twitter username
returns user object
52 53 54 55 56 57 58 59 |
# File 'lib/fake_friends.rb', line 52 def initialize(username) @username = username @name = FakeFriend.list[username][:name] @location = FakeFriend.list[username][:location] @description = FakeFriend.list[username][:description] @url = FakeFriend.list[username][:url] @posts = FakeFriend.list[username][:posts] end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
10 11 12 |
# File 'lib/fake_friends.rb', line 10 def description @description end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
10 11 12 |
# File 'lib/fake_friends.rb', line 10 def location @location end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/fake_friends.rb', line 10 def name @name end |
#posts ⇒ Object (readonly)
Returns the value of attribute posts.
10 11 12 |
# File 'lib/fake_friends.rb', line 10 def posts @posts end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
10 11 12 |
# File 'lib/fake_friends.rb', line 10 def url @url end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
10 11 12 |
# File 'lib/fake_friends.rb', line 10 def username @username end |
Class Method Details
.find_by(options) ⇒ Object
FakeFriend.find_by(options)
options <hash> id: n <int>
position in the users list, 1-101
username: str <string>
twitter username
Example: FakeFriend.find_by(id: 101)
> #<User:0x007ff0f286e2d8 …>
returns the requested user object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fake_friends.rb', line 34 def self.find_by() if [:id] && [:id].between?(1, FakeFriend.list.count) username = FakeFriend.list.keys[[:id]-1] FakeFriend.new(username) elsif [:username] && FakeFriend.list.keys.include?([:username]) FakeFriend.new([:username]) else raise ArgumentError, "Requested user not found in library." end end |
.gather(n) ⇒ Object
Friend.gather(n) returns an array of n user objects
14 15 16 17 18 |
# File 'lib/fake_friends.rb', line 14 def self.gather(n) raise ArgumentError, "Can only gather 1 to 101 FakeFriends" unless n.between?(1, 101) users = FakeFriend.list.keys.sample(n) users.map{ |username| FakeFriend.new(username) } end |
Instance Method Details
#avatar_url(size) ⇒ Object
avatar_url(size) returns the user’s uiFaces url in the closest available size
63 64 65 66 67 |
# File 'lib/fake_friends.rb', line 63 def avatar_url(size) valid_sizes = [128, 64, 48, 24] size = valid_sizes.min { |a,b| (size-a).abs <=> (size-b).abs } "https://s3.amazonaws.com/uifaces/faces/twitter/#{username}/#{size}.jpg" end |