Class: ReVIEW::Node

Inherits:
Object show all
Defined in:
lib/review/node.rb,
lib/review/compiler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contentObject

Returns the value of attribute content.



5
6
7
# File 'lib/review/node.rb', line 5

def content
  @content
end

Instance Method Details

#inspectObject



44
45
46
# File 'lib/review/node.rb', line 44

def inspect
  self.to_json
end

#to_docObject



11
12
13
# File 'lib/review/node.rb', line 11

def to_doc
  to_s_by(:to_doc)
end

#to_json(*args) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/review/node.rb', line 28

def to_json(*args)
  if content.kind_of? String
    val = '"'+@content.gsub(/\"/,'\\"').gsub(/\n/,'\\n')+'"'
  elsif content.nil?
    val = "null"
  elsif !content.kind_of? Array
    val = @content.to_json
  else
    val = "["+@content.map(&:to_json).join(",")+"]"
  end
  '{"ruleName":"' + self.class.to_s.sub(/ReVIEW::/,"").sub(/Node$/,"") + '",' +
    "\"offset\":#{position.pos},\"line\":#{position.line},\"column\":#{position.col}," +
    '"childNodes":' + val +
    '}'
end

#to_rawObject



7
8
9
# File 'lib/review/node.rb', line 7

def to_raw
  to_s_by(:to_raw)
end

#to_s_by(meth) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/review/node.rb', line 15

def to_s_by(meth)
  if content.kind_of? String
    @content
  elsif content.nil?
    nil
  elsif !content.kind_of? Array
    @content.__send__(meth)
  else
    ##@content.map(&meth).join("")
    @content.map{|o| o.__send__(meth)}.join("")
  end
end