Class: Printers::Xml::Variable

Inherits:
Object
  • Object
show all
Defined in:
lib/debugger/printers/xml.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value, kind = nil) ⇒ Variable

Returns a new instance of Variable.



96
97
98
99
100
# File 'lib/debugger/printers/xml.rb', line 96

def initialize(name, value, kind = nil)
  @name = name.to_s
  @value = value
  @kind = kind
end

Instance Attribute Details

#kindObject (readonly)

Returns the value of attribute kind.



95
96
97
# File 'lib/debugger/printers/xml.rb', line 95

def kind
  @kind
end

#nameObject (readonly)

Returns the value of attribute name.



95
96
97
# File 'lib/debugger/printers/xml.rb', line 95

def name
  @name
end

Instance Method Details

#has_children?Boolean

Returns:

  • (Boolean)


102
103
104
105
106
107
108
109
110
# File 'lib/debugger/printers/xml.rb', line 102

def has_children?
  if @value.is_a?(Array) || @value.is_a?(Hash)
    !@value.empty?
  else
    !@value.instance_variables.empty? || !@value.class.class_variables.empty?
  end
rescue
  false
end

#idObject



133
134
135
136
137
# File 'lib/debugger/printers/xml.rb', line 133

def id
  @value.respond_to?(:object_id) ? "%#+x" % @value.object_id : nil
rescue
  nil
end

#to_hashObject



145
146
147
# File 'lib/debugger/printers/xml.rb', line 145

def to_hash
  {name: @name, kind: @kind, value: value, type: type, has_children: has_children?, id: id}
end

#typeObject



139
140
141
142
143
# File 'lib/debugger/printers/xml.rb', line 139

def type
  @value.class
rescue
  "Undefined"
end

#valueObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/debugger/printers/xml.rb', line 112

def value
  if @value.is_a?(Array) || @value.is_a?(Hash)
    if has_children?
      "#{@value.class} (#{@value.size} element(s))"
    else
      "Empty #{@value.class}"
    end
  else
    value_str = @value.nil? ? 'nil' : @value.to_s
    if !value_str.is_a?(String)
      "ERROR: #{@value.class}.to_s method returns #{value_str.class}. Should return String."
    elsif binary_data?(value_str)
      "[Binary Data]"
    else
      value_str.gsub(/^(")(.*)(")$/, '\2')
    end
  end
rescue => e
  "<raised exception: #{e}>"
end