Class: Desmos::User

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

Direct Known Subclasses

Student, Tutor

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ User

Returns a new instance of User.

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
12
13
14
15
# File 'lib/desmos/user.rb', line 5

def initialize(options = {})
  options.recursive_symbolize_keys!
  @type        = 'user'
  @hash        = options[:hash]

  raise ArgumentError, ':id is a required attribute' unless options[:id]
  @id = options[:id]

  raise ArgumentError, ':name is a required attribute' unless options[:name]
  @name = options[:name]
end

Instance Attribute Details

#hashObject

Returns the value of attribute hash.



3
4
5
# File 'lib/desmos/user.rb', line 3

def hash
  @hash
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/desmos/user.rb', line 3

def id
  @id
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/desmos/user.rb', line 3

def name
  @name
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/desmos/user.rb', line 3

def type
  @type
end

Class Method Details

.build_from_hash(options = {}) ⇒ Object



17
18
19
20
21
22
# File 'lib/desmos/user.rb', line 17

def self.build_from_hash(options = {})
  options.recursive_symbolize_keys!
  return if options[:id].blank?
  return if options[:name].blank?
  new(options)
end

Instance Method Details

#request_optionsObject



24
25
26
27
28
29
30
31
# File 'lib/desmos/user.rb', line 24

def request_options
  options = {}
  options.merge!(:user_id   => id)
  options.merge!(:user_name => name)
  options.merge!(:user_type => type)
  options.merge!(:user_hash => hash) if hash
  options
end