Class: Cwsrb::User

Inherits:
Object
  • Object
show all
Defined in:
lib/cwsrb/data.rb

Overview

The User class represents a member of ConWorkShop.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: '', name: '', gender: 'Other', bio: '', country: 'Unknown', karma: [0, 0]) ⇒ User

Initializes a new User instance with an options hash.

Parameters:

  • id (String, Integer) (defaults to: '')

    The user's ID: a bunch of numbers that may or may not be prefixed with 'S'. Defaults to an empty string.

  • name (String) (defaults to: '')

    The user's name. Defaults to an empty string.

  • gender (String) (defaults to: 'Other')

    The user's gender, one of "Male", "Female", "Cyborg" or "Other". Defaults to "Other".

  • bio (String) (defaults to: '')

    The user's bio or about section. Defaults to an empty string.

  • country (String) (defaults to: 'Unknown')

    The user's country. Defaults to "Unknown".

  • karma (Array<(Integer, Integer)>) (defaults to: [0, 0])

    The user's karma counts. First is upvotes, second is downvotes. Defaults to zero for both.


38
39
40
41
42
43
44
45
# File 'lib/cwsrb/data.rb', line 38

def initialize(id: '', name: '', gender: 'Other', bio: '', country: 'Unknown', karma: [0, 0])
  @id = id
  @name = name
  @gender = gender
  @bio = bio
  @country = country
  @karma = karma
end

Instance Attribute Details

#bioString (readonly)

Returns The User's bio, max 1000 characters.

Returns:

  • (String)

    The User's bio, max 1000 characters


17
18
19
# File 'lib/cwsrb/data.rb', line 17

def bio
  @bio
end

#countryString (readonly)

Returns The User's country.

Returns:

  • (String)

    The User's country


20
21
22
# File 'lib/cwsrb/data.rb', line 20

def country
  @country
end

#genderString (readonly)

Returns The User's gender, one of "Male", "Female", "Cyborg" or "Other".

Returns:

  • (String)

    The User's gender, one of "Male", "Female", "Cyborg" or "Other"


14
15
16
# File 'lib/cwsrb/data.rb', line 14

def gender
  @gender
end

#idString, Integer (readonly)

Returns The User's ID.

Returns:

  • (String, Integer)

    The User's ID


7
8
9
# File 'lib/cwsrb/data.rb', line 7

def id
  @id
end

#karmaArray<(Integer, Integer)> (readonly)

Returns The User's karma counts; first one is upvotes and second one is downvotes.

Returns:

  • (Array<(Integer, Integer)>)

    The User's karma counts; first one is upvotes and second one is downvotes


24
25
26
# File 'lib/cwsrb/data.rb', line 24

def karma
  @karma
end

#nameString (readonly)

Returns The User's name.

Returns:

  • (String)

    The User's name


10
11
12
# File 'lib/cwsrb/data.rb', line 10

def name
  @name
end

Instance Method Details

Generates a CWS link to this user.

Returns:

  • (String)

    The generated link.


49
50
51
# File 'lib/cwsrb/data.rb', line 49

def generate_link
  CWS_BASE + "/view_profile.php?m=#{@id}"
end

#inspectString

inspect method, with all of User's attributes.

Returns:

  • (String)

    A more meaningful output than that of the default


56
57
58
# File 'lib/cwsrb/data.rb', line 56

def inspect
  "<User id=#{@id} name=#{@name} gender=#{gender} bio=#{bio} country=#{country} karma=#{karma}>"
end