Class: Rubyhexagon::User

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

Overview

Class to hold user information for users on e621.

Author:

  • Maxine Michalski

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

Author:

  • Maxine Michalski

Since:

  • 1.0.0



46
47
48
49
# File 'lib/rubyhexagon/user.rb', line 46

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



37
38
39
# File 'lib/rubyhexagon/user.rb', line 37

def created_at
  @created_at
end

#idInteger (readonly)

Returns id of user.

Returns:

  • (Integer)

    id of user

Since:

  • 1.0.0



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

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



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

def level
  @level
end

#nameString (readonly)

Returns name of user.

Returns:

  • (String)

    name of user

Since:

  • 1.0.0



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

def name
  @name
end

Instance Method Details

#==(other) ⇒ TrueClass, FalseClass

Comparison method for User objects

Returns:

  • (TrueClass, FalseClass)

Author:

  • Maxine Michalski

Since:

  • 1.0.0



76
77
78
79
80
81
82
# File 'lib/rubyhexagon/user.rb', line 76

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

#showUser

Returns a filled User object

Returns:

  • (User)

    filled out user object

Author:

  • Maxine Michalski

Since:

  • 1.0.0



65
66
67
68
69
# File 'lib/rubyhexagon/user.rb', line 65

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

#show!Object

Fill this object with user data.

Author:

  • Maxine Michalski

Since:

  • 1.0.0



54
55
56
57
58
# File 'lib/rubyhexagon/user.rb', line 54

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