Class: E621::User

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

Overview

Class to hold user information for users on e621.

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ Object

Initializer for User.

Parameters:

  • user (Hash)

    user data, fetched from e621

Since:

  • 1.0.0



44
45
46
47
# File 'lib/rubyhexagon/user.rb', line 44

def initialize(user)
  @id = user[:id].to_i
  @name = user[:name]
end

Instance Attribute Details

#created_atTime (readonly)

Returns registration time of this user.

Returns:

  • (Time)

    registration time of this user

Since:

  • 1.0.0



35
36
37
# File 'lib/rubyhexagon/user.rb', line 35

def created_at
  @created_at
end

#idInteger (readonly)

Returns id of user.

Returns:

  • (Integer)

    id of user

Since:

  • 1.0.0



26
27
28
# File 'lib/rubyhexagon/user.rb', line 26

def id
  @id
end

#levelLevel (readonly)

Returns level of access, this user holds.

Returns:

  • (Level)

    level of access, this user holds

Since:

  • 1.0.0



32
33
34
# File 'lib/rubyhexagon/user.rb', line 32

def level
  @level
end

#nameString (readonly)

Returns name of user.

Returns:

  • (String)

    name of user

Since:

  • 1.0.0



29
30
31
# File 'lib/rubyhexagon/user.rb', line 29

def name
  @name
end

Instance Method Details

#==(other) ⇒ TrueClass, FalseClass

Comparison method for User objects

Returns:

  • (TrueClass, FalseClass)

Since:

  • 1.0.0



74
75
76
# File 'lib/rubyhexagon/user.rb', line 74

def ==(other)
  other.is_a?(User) && @id == other.id && @name == other.name
end

#showUser

Returns a filled User object

Returns:

  • (User)

    filled out user object

Since:

  • 1.0.0



63
64
65
66
67
# File 'lib/rubyhexagon/user.rb', line 63

def show
  user = User.new(id: @id, name: @name)
  user.show!
  user
end

#show!Object

Fill this object with user data.

Since:

  • 1.0.0



52
53
54
55
56
# File 'lib/rubyhexagon/user.rb', line 52

def show!
  user = API.new.fetch('user', 'show', id: @id)
  @level      = Level.new(user[:level].to_i)
  @created_at = Time.parse(user[:created_at])
end