-
Notifications
You must be signed in to change notification settings - Fork 10
/
inspects.rb
70 lines (63 loc) · 1.51 KB
/
inspects.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
63
64
65
66
67
68
69
70
require 'rdf'
# override several inspect functions to improve output for what we're doing
class RDF::Literal
def inspect
"\"#{escape(value)}\" R:L:(#{self.class.to_s.match(/([^:]*)$/)})"
end
end
class RDF::URI
def inspect
"RDF::URI(#{to_base})"
end
end
class RDF::Node
def inspect
"RDF::Node(#{to_base})"
end
end
class RDF::Graph
def inspect
"RDF::Graph(graph_name: #{self.graph_name || 'nil'})"
end
end
class RDF::Query
def inspect
"RDF::Query(#{graph_name ? graph_name.to_sxp : 'nil'})#{patterns.inspect}"
end
end
class Array
alias_method :inspect_without_formatting, :inspect
def inspect_with_formatting
if all? { |item| item.is_a?(Hash) }
string = "[\n"
each do |item|
string += " {\n"
item.keys.map(&:to_s).sort.each do |key|
string += " #{key}: #{item[key.to_sym].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.map(&:to_s).sort.each do |key|
string += " #{key}: #{item.bindings[key.to_sym].inspect}\n"
end
string += " },\n"
end
string += "]"
string
else
inspect_without_formatting
end
end
alias_method :inspect, :inspect_with_formatting
end
class RDF::Query::Solutions
def inspect
string = "vars: #{variable_names.join(",")}\n#{to_a.inspect}"
end
end