Class: SPOT::Resources::Message
- Inherits:
-
Object
- Object
- SPOT::Resources::Message
- Defined in:
- lib/spot-gps/resources/message.rb
Instance Attribute Summary collapse
-
#battery_state ⇒ Object
readonly
Returns the value of attribute battery_state.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#hidden ⇒ Object
readonly
Returns the value of attribute hidden.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#latitude ⇒ Object
readonly
Returns the value of attribute latitude.
-
#longitude ⇒ Object
readonly
Returns the value of attribute longitude.
-
#messenger_id ⇒ Object
readonly
Returns the value of attribute messenger_id.
-
#messenger_model ⇒ Object
readonly
Returns the value of attribute messenger_model.
-
#messenger_name ⇒ Object
readonly
Returns the value of attribute messenger_name.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#show_custom_message ⇒ Object
readonly
Returns the value of attribute show_custom_message.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(object, response = nil) ⇒ Message
constructor
A new instance of Message.
- #inspect ⇒ Object
- #to_h ⇒ Object
- #to_raw_h ⇒ Object
Constructor Details
#initialize(object, response = nil) ⇒ Message
Returns a new instance of Message.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/spot-gps/resources/message.rb', line 19 def initialize(object, response = nil) @id = object.fetch('id') @created_at = Time.at(object.fetch('unixTime')) @type = object.fetch('messageType') @latitude = object.fetch('latitude') @longitude = object.fetch('longitude') @battery_state = object.fetch('batteryState') @hidden = object.fetch('hidden') == 1 @show_custom_message = object.fetch('showCustomMsg') == "Y" @content = object.fetch('messageContent', nil) @messenger_id = object.fetch('messengerId') @messenger_name = object.fetch('messengerName') @messenger_model = object.fetch('modelId') @object = object @response = response end |
Instance Attribute Details
#battery_state ⇒ Object (readonly)
Returns the value of attribute battery_state.
9 10 11 |
# File 'lib/spot-gps/resources/message.rb', line 9 def battery_state @battery_state end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
12 13 14 |
# File 'lib/spot-gps/resources/message.rb', line 12 def content @content end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
5 6 7 |
# File 'lib/spot-gps/resources/message.rb', line 5 def created_at @created_at end |
#hidden ⇒ Object (readonly)
Returns the value of attribute hidden.
10 11 12 |
# File 'lib/spot-gps/resources/message.rb', line 10 def hidden @hidden end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/spot-gps/resources/message.rb', line 4 def id @id end |
#latitude ⇒ Object (readonly)
Returns the value of attribute latitude.
7 8 9 |
# File 'lib/spot-gps/resources/message.rb', line 7 def latitude @latitude end |
#longitude ⇒ Object (readonly)
Returns the value of attribute longitude.
8 9 10 |
# File 'lib/spot-gps/resources/message.rb', line 8 def longitude @longitude end |
#messenger_id ⇒ Object (readonly)
Returns the value of attribute messenger_id.
13 14 15 |
# File 'lib/spot-gps/resources/message.rb', line 13 def messenger_id @messenger_id end |
#messenger_model ⇒ Object (readonly)
Returns the value of attribute messenger_model.
15 16 17 |
# File 'lib/spot-gps/resources/message.rb', line 15 def messenger_model @messenger_model end |
#messenger_name ⇒ Object (readonly)
Returns the value of attribute messenger_name.
14 15 16 |
# File 'lib/spot-gps/resources/message.rb', line 14 def messenger_name @messenger_name end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
17 18 19 |
# File 'lib/spot-gps/resources/message.rb', line 17 def response @response end |
#show_custom_message ⇒ Object (readonly)
Returns the value of attribute show_custom_message.
11 12 13 |
# File 'lib/spot-gps/resources/message.rb', line 11 def @show_custom_message end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/spot-gps/resources/message.rb', line 6 def type @type end |
Instance Method Details
#inspect ⇒ Object
53 54 55 56 57 58 |
# File 'lib/spot-gps/resources/message.rb', line 53 def inspect attr_list = to_h.map { |key, value| "#{key}: #{value.inspect}" }.join(', ') "#<#{self.class} #{attr_list}>" end |
#to_h ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/spot-gps/resources/message.rb', line 37 def to_h @hash ||= begin attribute_ivars = (instance_variables - [:@response, :@object, :@hash]) attribute_ivars.each_with_object({}) do |ivar, hash| hash[ivar.to_s.delete('@').to_sym] = instance_variable_get(ivar) end end end |
#to_raw_h ⇒ Object
49 50 51 |
# File 'lib/spot-gps/resources/message.rb', line 49 def to_raw_h @object end |