class ReVIEW::Node

Attributes

content[RW]

Public Instance Methods

inspect() click to toggle source
# File lib/review/node.rb, line 44
def inspect
  self.to_json
end
to_doc() click to toggle source
# File lib/review/node.rb, line 11
def to_doc
  to_s_by(:to_doc)
end
to_json(*args) click to toggle source
# 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_raw() click to toggle source
# File lib/review/node.rb, line 7
def to_raw
  to_s_by(:to_raw)
end
to_s_by(meth) click to toggle source
# 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