Class: Magellan::Gcs::Proxy::MessageWrapper::Attrs

Inherits:
Object
  • Object
show all
Defined in:
lib/magellan/gcs/proxy/message_wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Attrs

Returns a new instance of Attrs.



57
58
59
# File 'lib/magellan/gcs/proxy/message_wrapper.rb', line 57

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



56
57
58
# File 'lib/magellan/gcs/proxy/message_wrapper.rb', line 56

def data
  @data
end

Instance Method Details

#[](key) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/magellan/gcs/proxy/message_wrapper.rb', line 61

def [](key)
  value = data[key]
  if value.is_a?(String) && value =~ /\A\[.*\]\z|\A\{.*\}\z/
    begin
      JSON.parse(value)
    rescue
      value
    end
  else
    value
  end
end

#include?(key) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/magellan/gcs/proxy/message_wrapper.rb', line 74

def include?(key)
  data.include?(key) || data.include?(key.to_sym)
end