Class: CtdDocumentation::User

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/ctd_documentation/models/user.rb

Overview

User Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(username = nil, password = nil, first_name = SKIP, last_name = SKIP, mail = SKIP) ⇒ User

Returns a new instance of User.



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/ctd_documentation/models/user.rb', line 57

def initialize(username = nil,
               password = nil,
               first_name = SKIP,
               last_name = SKIP,
               mail = SKIP)
  @username = username
  @password = password
  @first_name = first_name unless first_name == SKIP
  @last_name = last_name unless last_name == SKIP
  @mail = mail unless mail == SKIP
end

Instance Attribute Details

#first_nameString

TODO: Write general description for this method

Returns:

  • (String)


22
23
24
# File 'lib/ctd_documentation/models/user.rb', line 22

def first_name
  @first_name
end

#last_nameString

TODO: Write general description for this method

Returns:

  • (String)


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

def last_name
  @last_name
end

#mailString

TODO: Write general description for this method

Returns:

  • (String)


30
31
32
# File 'lib/ctd_documentation/models/user.rb', line 30

def mail
  @mail
end

#passwordString

TODO: Write general description for this method

Returns:

  • (String)


18
19
20
# File 'lib/ctd_documentation/models/user.rb', line 18

def password
  @password
end

#usernameString

TODO: Write general description for this method

Returns:

  • (String)


14
15
16
# File 'lib/ctd_documentation/models/user.rb', line 14

def username
  @username
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/ctd_documentation/models/user.rb', line 70

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.

  username = hash.key?('username') ? hash['username'] : nil
  password = hash.key?('password') ? hash['password'] : nil
  first_name = hash.key?('first_name') ? hash['first_name'] : SKIP
  last_name = hash.key?('last_name') ? hash['last_name'] : SKIP
  mail = hash.key?('mail') ? hash['mail'] : SKIP

  # Create object from extracted values.

  User.new(username,
           password,
           first_name,
           last_name,
           mail)
end

.namesObject

A mapping from model property names to API property names.



33
34
35
36
37
38
39
40
41
# File 'lib/ctd_documentation/models/user.rb', line 33

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['username'] = 'username'
  @_hash['password'] = 'password'
  @_hash['first_name'] = 'first_name'
  @_hash['last_name'] = 'last_name'
  @_hash['mail'] = 'mail'
  @_hash
end

.nullablesObject

An array for nullable fields



53
54
55
# File 'lib/ctd_documentation/models/user.rb', line 53

def self.nullables
  []
end

.optionalsObject

An array for optional fields



44
45
46
47
48
49
50
# File 'lib/ctd_documentation/models/user.rb', line 44

def self.optionals
  %w[
    first_name
    last_name
    mail
  ]
end