debugvisualizer 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99b5095a86aff837ff3210a772f31625ec184c6393076a86df47137f10a8da38
4
- data.tar.gz: e7eda2e94c63f0428960bbd1185e347152c356da410ad9646327983255283797
3
+ metadata.gz: 17a5df625ac442f50c8f8455ce630d98afcaec3eab93e004d72374f08ba2d1c3
4
+ data.tar.gz: 9e08125199a22ccef1d45d5ae04545faff070e7e6085aaf78ec4bdd1745dd7d1
5
5
  SHA512:
6
- metadata.gz: 28059f5e1c89d4642e99e0672ed18d677b4b87430cf8f33ebdb23ebfef09462f054fd865d1bf6b02bfb4915f826a7706482c2bddda50b616cd6ad7f14eec3899
7
- data.tar.gz: bf6103a0494df88e7ba175402efae691f6ab285b7efa936c05907100af1db59141578a7094cc9ab4d8b655223913854aae4dfb85779b870f32f77804fca735e3
6
+ metadata.gz: 3cf9bf5a9cb3fb0b28ea54fea1af00dd773fefeeb8c80423b41d3bfd1deb15cb746fd3ff9c45232dac74f66377a863ba3689105a6307b798171f9bd191dd1258
7
+ data.tar.gz: 4d70f1ac9a6c2a1d3a60579909e2e603af2463615c18a91a79f822898af17db4a55eb2bb27139b10f675de5cfb0c7823c4a33d17a095f271ee5da9061246b5db
@@ -1,43 +1,72 @@
1
1
  module DebugVisualizer
2
2
  DebugVisualizer.register do |data|
3
- if data.is_a?(Array)
4
- new_data = nil
5
- name = ""
6
- if data.all? {|v| v.is_a?(Integer) || v.is_a?(Float) }
7
- new_data = {
3
+ if data.is_a?(Array) && data.all? {|v| v.is_a?(Integer) || v.is_a?(Float) }
4
+ {
5
+ id: "array_as_line_chart",
6
+ name: "Array As Line Chart",
7
+ priority: 100,
8
+ data: {
8
9
  "kind":{ "plotly": true },
9
10
  "data":[
10
11
  { "y": data },
11
12
  ]
12
13
  }
13
- name = "Array As Plot"
14
- else
15
- columns = []
16
- data.each{|elem|
17
- columns << {content: elem.to_s, tag: elem.to_s}
14
+ }
15
+ end
16
+ end
17
+
18
+ DebugVisualizer.register do |data|
19
+ if data.is_a?(Array)
20
+ columns = []
21
+ data.each{|elem|
22
+ columns << {content: elem.to_s}
23
+ }
24
+ new_data = {
25
+ "kind": { "grid": true },
26
+ "rows": [
27
+ {
28
+ "columns": columns
29
+ }
30
+ ]
31
+ }
32
+ {
33
+ id: "array_as_grid",
34
+ name: "Array As Grid",
35
+ priority: 80,
36
+ data: new_data
37
+ }
38
+ end
39
+ end
40
+
41
+ DebugVisualizer.register do |data|
42
+ if data.is_a?(Array) && data.all? {|v| v.is_a?(Hash) }
43
+ {
44
+ id: "array_as_table",
45
+ name: "Array As Table",
46
+ priority: 100,
47
+ data: {
48
+ kind: { table: true },
49
+ rows: data
18
50
  }
19
- new_data = {
20
- "kind": { "grid": true },
21
- "text": "test",
22
- "columnLabels": [
23
- {
24
- "label": "test"
25
- }
26
- ],
27
- "rows": [
28
- {
29
- "label": "foo",
30
- "columns": columns
31
- }
51
+ }
52
+ end
53
+ end
54
+
55
+ DebugVisualizer.register do |data|
56
+ if data.is_a?(Array) && data.all? {|v| v.is_a?(Integer) || v.is_a?(Float) }
57
+ {
58
+ id: "array_as_bar_chart",
59
+ name: "Array As Bar Chart",
60
+ priority: 50,
61
+ data: {
62
+ kind: { plotly: true },
63
+ data: [
64
+ {
65
+ y: data,
66
+ type: :bar
67
+ }
32
68
  ]
33
69
  }
34
- name = "Array As Grid"
35
- end
36
- {
37
- id: "array_visualizer",
38
- name: name,
39
- priority: 30,
40
- data: new_data
41
70
  }
42
71
  end
43
72
  end
@@ -2,11 +2,71 @@ module DebugVisualizer
2
2
  DebugVisualizer.register do |data|
3
3
  if data.is_a?(Hash)
4
4
  {
5
- id: "hash_visualizer",
5
+ id: "hash_as_table",
6
6
  name: "Hash As Table",
7
+ priority: 50,
7
8
  data: {
8
9
  kind: { table: true },
9
- rows: [data]
10
+ rows: data.map{|key, val| {key: key, value: val}}
11
+ }
12
+ }
13
+ end
14
+ end
15
+
16
+ DebugVisualizer.register do |data|
17
+ if data.is_a?(Hash) && data.values.all? {|v| v.is_a?(Integer) || v.is_a?(Float) }
18
+ {
19
+ id: "hash_as_line_chart",
20
+ name: "Hash As Line Chart",
21
+ priority: 80,
22
+ data: {
23
+ kind: { plotly: true },
24
+ data: [
25
+ {
26
+ x: data.keys,
27
+ y: data.values
28
+ }
29
+ ]
30
+ }
31
+ }
32
+ end
33
+ end
34
+
35
+ DebugVisualizer.register do |data|
36
+ if data.is_a?(Hash) && data.values.all? {|v| v.is_a?(Integer) || v.is_a?(Float) }
37
+ {
38
+ id: "hash_as_pie_chart",
39
+ name: "Hash As Pie Chart",
40
+ priority: 20,
41
+ data: {
42
+ kind: { plotly: true },
43
+ data: [
44
+ {
45
+ labels: data.keys,
46
+ values: data.values,
47
+ type: :pie
48
+ }
49
+ ]
50
+ }
51
+ }
52
+ end
53
+ end
54
+
55
+ DebugVisualizer.register do |data|
56
+ if data.is_a?(Hash) && data.values.all? {|v| v.is_a?(Integer) || v.is_a?(Float) }
57
+ {
58
+ id: "hash_as_bar_chart",
59
+ name: "Hash As Bar Chart",
60
+ priority: 100,
61
+ data: {
62
+ kind: { plotly: true },
63
+ data: [
64
+ {
65
+ x: data.keys,
66
+ y: data.values,
67
+ type: :bar
68
+ }
69
+ ]
10
70
  }
11
71
  }
12
72
  end
@@ -0,0 +1,59 @@
1
+ module DebugVisualizer
2
+ DebugVisualizer.register do |data|
3
+ if (defined?(Nokogiri::HTML4::Document) && data.kind_of?(Nokogiri::HTML4::Document)) ||
4
+ (defined?(Nokogiri::XML::Document) && data.kind_of?(Nokogiri::XML::Document))
5
+ {
6
+ id: "nokogiri_visualizer",
7
+ name: "Nokogiri As Tree",
8
+ data: {
9
+ kind: { tree: true },
10
+ root: get_tree(data.children).last
11
+ }
12
+ }
13
+ end
14
+ end
15
+
16
+ def self.get_tree(elems)
17
+ result = []
18
+ elems.each{|elem|
19
+ child = []
20
+ elem.attributes.each{|key, val|
21
+ items = []
22
+ items << {
23
+ text: "#{key}: ",
24
+ emphasis: 'style2'
25
+ }
26
+ items << {
27
+ text: val.value,
28
+ emphasis: 'style2'
29
+ }
30
+ child << {
31
+ items: items,
32
+ children: []
33
+ }
34
+ }
35
+ if elem.children
36
+ child.push *get_tree(elem.children)
37
+ end
38
+ next if elem.name == 'text'
39
+
40
+ tree = {
41
+ items: [
42
+ {
43
+ text: elem.name,
44
+ emphasis: 'style1'
45
+ }
46
+ ],
47
+ children: child
48
+ }
49
+ text = elem.xpath('text()').text
50
+ if text && text.strip != ""
51
+ tree[:items] << {
52
+ text: ' ' * 2 + text.strip
53
+ }
54
+ end
55
+ result << tree
56
+ }
57
+ result
58
+ end
59
+ end
@@ -15,7 +15,7 @@ module DebugVisualizer
15
15
  def self.get_tree(elems)
16
16
  result = []
17
17
  elems.each_element{|elem|
18
- child = []
18
+ children = []
19
19
  elem.attributes.each_attribute{|atr|
20
20
  items = []
21
21
  items << {
@@ -26,13 +26,13 @@ module DebugVisualizer
26
26
  text: atr.value,
27
27
  emphasis: 'style2'
28
28
  }
29
- child << {
29
+ children << {
30
30
  items: items,
31
31
  children: []
32
32
  }
33
33
  }
34
34
  if elem.has_elements?
35
- child.push *get_tree(elem)
35
+ children.push *get_tree(elem)
36
36
  end
37
37
  tree = {
38
38
  items: [
@@ -41,7 +41,7 @@ module DebugVisualizer
41
41
  emphasis: 'style1'
42
42
  }
43
43
  ],
44
- children: child
44
+ children: children
45
45
  }
46
46
  if elem.text && elem.text.strip != ""
47
47
  tree[:items] << {
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DebugVisualizer
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
@@ -116,3 +116,4 @@ require_relative 'debugvisualizer/hash'
116
116
  require_relative 'debugvisualizer/to_string'
117
117
  require_relative 'debugvisualizer/string_diff'
118
118
  require_relative 'debugvisualizer/rexml'
119
+ require_relative 'debugvisualizer/nokogiri'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: debugvisualizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naoto Ono
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-04 00:00:00.000000000 Z
11
+ date: 2022-12-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: debugvisualizer generates JSON based on VS Code Debug Visualizer protocol
14
14
  email:
@@ -26,6 +26,7 @@ files:
26
26
  - lib/debugvisualizer/active_record.rb
27
27
  - lib/debugvisualizer/array.rb
28
28
  - lib/debugvisualizer/hash.rb
29
+ - lib/debugvisualizer/nokogiri.rb
29
30
  - lib/debugvisualizer/rexml.rb
30
31
  - lib/debugvisualizer/string_diff.rb
31
32
  - lib/debugvisualizer/to_string.rb