Module: XmlTreeViewer

Defined in:
lib/xml_tree_viewer.rb,
lib/xml_tree_viewer/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
"0.1.2"

Class Method Summary collapse

Class Method Details

.draw_hash_line(name, mode, offset, key) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/xml_tree_viewer.rb', line 119

def self.draw_hash_line( name, mode, offset, key )
    lines = []
    if !mode.eql?( :silent )
        level = name[ 1, name.length ].to_i
        
        str = ''
        edge = self.draw_hash_line_edge( level, :edge, offset )
        str = "#{edge} #{key.name}"
        lines.push( str )

        case mode
        when :short
        when :detail
            empty = self.draw_hash_line_edge( level, :empty, offset )
            str = "#{empty} doc.css('#{key.css_path}')"
            lines.push( str )
        end
    end

    return lines
end

.draw_hash_line_edge(l, type, offset) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/xml_tree_viewer.rb', line 95

def self.draw_hash_line_edge( l, type, offset )
    str = ''

    for i in 1..( ( l - 1 ) * offset )
        str += ' '
    end

    case type
    when :edge
        if l > 1
            str += ""
            str += ""
            str += " "
        else
            str += '   '
        end
    when :empty
        str += '   '
    end

    return str
end

.generate(xml, mode) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/xml_tree_viewer.rb', line 25

def self.generate( xml, mode )

  if validate( xml, mode )
    self.draw_xml( xml, mode )
  end
  
  return true
end

.helperObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/xml_tree_viewer.rb', line 10

def self.helper()
  result = <<-EOXML
<employees>
<employee status="active">
  <fullname>John Doe</fullname>
</employee>
<employee status="inactive">
  <fullname>Max Mustermann</fullname>
</employee>
</employees>
EOXML
  return result
end