File: node.rb

package info (click to toggle)
ruby-nokogiri 1.10.0%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,088 kB
  • sloc: xml: 28,081; ruby: 16,687; java: 13,293; ansic: 4,954; yacc: 265; sh: 76; makefile: 19
file content (56 lines) | stat: -rw-r--r-- 1,646 bytes parent folder | download | duplicates (6)
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
module Nokogiri
  module XML
    module PP
      module Node
        def inspect # :nodoc:
          attributes = inspect_attributes.reject { |x|
            begin
              attribute = send x
              !attribute || (attribute.respond_to?(:empty?) && attribute.empty?)
            rescue NoMethodError
              true
            end
          }.map { |attribute|
            "#{attribute.to_s.sub(/_\w+/, 's')}=#{send(attribute).inspect}"
          }.join ' '
          "#<#{self.class.name}:#{sprintf("0x%x", object_id)} #{attributes}>"
        end

        def pretty_print pp # :nodoc:
          nice_name = self.class.name.split('::').last
          pp.group(2, "#(#{nice_name}:#{sprintf("0x%x", object_id)} {", '})') do

            pp.breakable
            attrs = inspect_attributes.map { |t|
              [t, send(t)] if respond_to?(t)
            }.compact.find_all { |x|
              if x.last
                if [:attribute_nodes, :children].include? x.first
                  !x.last.empty?
                else
                  true
                end
              end
            }

            pp.seplist(attrs) do |v|
              if [:attribute_nodes, :children].include? v.first
                pp.group(2, "#{v.first.to_s.sub(/_\w+$/, 's')} = [", "]") do
                  pp.breakable
                  pp.seplist(v.last) do |item|
                    pp.pp item
                  end
                end
              else
                pp.text "#{v.first} = "
                pp.pp v.last
              end
            end
            pp.breakable

          end
        end
      end
    end
  end
end