Class: Asdawqw::MessageModel
- Defined in:
- lib/asdawqw/models/message_model.rb
Overview
Model for one message
Instance Attribute Summary collapse
-
#created_at ⇒ String
Time when message created.
-
#message ⇒ String
Message text.
-
#user ⇒ UserEnum
Who created message GUEST.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
Instance Method Summary collapse
-
#initialize(message = nil, created_at = nil, user = nil) ⇒ MessageModel
constructor
A new instance of MessageModel.
Methods inherited from BaseModel
Constructor Details
#initialize(message = nil, created_at = nil, user = nil) ⇒ MessageModel
Returns a new instance of MessageModel.
30 31 32 33 34 35 36 |
# File 'lib/asdawqw/models/message_model.rb', line 30 def initialize( = nil, created_at = nil, user = nil) @message = @created_at = created_at @user = user end |
Instance Attribute Details
#created_at ⇒ String
Time when message created
15 16 17 |
# File 'lib/asdawqw/models/message_model.rb', line 15 def created_at @created_at end |
#message ⇒ String
Message text
11 12 13 |
# File 'lib/asdawqw/models/message_model.rb', line 11 def @message end |
#user ⇒ UserEnum
Who created message GUEST
19 20 21 |
# File 'lib/asdawqw/models/message_model.rb', line 19 def user @user end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/asdawqw/models/message_model.rb', line 39 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. = hash['message'] created_at = hash['createdAt'] user = hash['user'] # Create object from extracted values. MessageModel.new(, created_at, user) end |
.names ⇒ Object
A mapping from model property names to API property names.
22 23 24 25 26 27 28 |
# File 'lib/asdawqw/models/message_model.rb', line 22 def self.names @_hash = {} if @_hash.nil? @_hash['message'] = 'message' @_hash['created_at'] = 'createdAt' @_hash['user'] = 'user' @_hash end |