Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/rdf/spec/inspects.rb

Instance Method Summary collapse

Instance Method Details

#inspect_with_formattingObject Also known as: inspect


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rdf/spec/inspects.rb', line 36

def inspect_with_formatting
  if all? { |item| item.is_a?(Hash) }
    string = "[\n"
    each do |item|
      string += "  {\n"
        item.keys.sort_by(&:to_s).each do |key|
          string += "      #{key.inspect}: #{item[key].inspect}\n"
        end
      string += "  },\n"
    end
    string += "]"
    string
  elsif all? { |item| item.is_a?(RDF::Query::Solution)}
    string = "[\n"
    each do |item|
      string += "  {\n"
        item.bindings.keys.sort_by(&:to_s).each do |key|
          string += "      #{key.inspect}: #{item.bindings[key].inspect}\n"
        end
      string += "  },\n"
    end
    string += "]"
    string
  else
    inspect_without_formatting
  end
end