class Byebug::Printers::Xml::Variable

Attributes

kind[R]
name[R]

Public Class Methods

new(name, value, kind = nil) click to toggle source
# File lib/byebug/printers/xml.rb, line 97
def initialize(name, value, kind = nil)
  @name = name.to_s
  @value = value
  @kind = kind
end

Public Instance Methods

has_children?() click to toggle source
# File lib/byebug/printers/xml.rb, line 103
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
id() click to toggle source
# File lib/byebug/printers/xml.rb, line 134
def id
  @value.respond_to?(:object_id) ? "%#+x" % @value.object_id : nil
rescue
  nil
end
to_hash() click to toggle source
# File lib/byebug/printers/xml.rb, line 146
def to_hash
  {name: @name, kind: @kind, value: value, type: type, has_children: has_children?, id: id}
end
type() click to toggle source
# File lib/byebug/printers/xml.rb, line 140
def type
  @value.class
rescue
  "Undefined"
end
value() click to toggle source
# File lib/byebug/printers/xml.rb, line 113
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

Private Instance Methods

binary_data?(string) click to toggle source
# File lib/byebug/printers/xml.rb, line 152
def binary_data?(string)
  string.count("\x00-\x7F", "^ -~\t\r\n").fdiv(string.size) > 0.3 || string.index("\x00") unless string.empty?
end