Class: Biostars::API::User

Inherits:
Object
  • Object
show all
Defined in:
lib/biostars/api/user.rb

Overview

General info about a user.

Author:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ User

Instantiate the Biostars::API::User.



27
28
29
30
31
# File 'lib/biostars/api/user.rb', line 27

def initialize(attributes)
	attributes.each do |k,v| 
		instance_variable_set "@#{k}", v unless v.nil?
	end
end

Instance Attribute Details

#date_joinedString (readonly)

Returns the date the user joined the website, as the number of days ago.

Returns:

  • (String)

    the date the user joined the website, as the number of days ago



9
10
11
# File 'lib/biostars/api/user.rb', line 9

def date_joined
  @date_joined
end

#idFixnum (readonly)

Returns the identifier of the user.

Returns:

  • (Fixnum)

    the identifier of the user



12
13
14
# File 'lib/biostars/api/user.rb', line 12

def id
  @id
end

#joined_days_agoString (readonly)

Returns the date the user joined the website, ISO 8601 format.

Returns:

  • (String)

    the date the user joined the website, ISO 8601 format



15
16
17
# File 'lib/biostars/api/user.rb', line 15

def joined_days_ago
  @joined_days_ago
end

#last_loginString (readonly)

Returns the date of the last login of the user, ISO 8601 format.

Returns:

  • (String)

    the date of the last login of the user, ISO 8601 format



18
19
20
# File 'lib/biostars/api/user.rb', line 18

def 
  @last_login
end

#nameString (readonly)

Returns the name of the user.

Returns:

  • (String)

    the name of the user.



21
22
23
# File 'lib/biostars/api/user.rb', line 21

def name
  @name
end

#vote_countFixnum (readonly)

Returns the number of votes given by the user.

Returns:

  • (Fixnum)

    the number of votes given by the user.



24
25
26
# File 'lib/biostars/api/user.rb', line 24

def vote_count
  @vote_count
end

Class Method Details

.find(id) ⇒ User

Finds user with the given id.

Parameters:

  • id (Fixnum)

    user id.

Returns:

  • (User)

    returns User object.

Raises:



38
39
40
41
# File 'lib/biostars/api/user.rb', line 38

def self.find(id)
	attributes = Biostars::API.get "user/#{id}"
	attributes ? new(attributes) : raise(Biostars::UserError)
end