Class: JsDuck::JsLiteralBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/jsduck/js_literal_builder.rb

Overview

Takes output of JsLiteralParser and converts it to string

Instance Method Summary collapse

Instance Method Details

#to_s(lit) ⇒ Object

Converts literal object definition to string



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/jsduck/js_literal_builder.rb', line 7

def to_s(lit)
  if lit[:type] == :string
    '"' + lit[:value] + '"'
  elsif lit[:type] == :array
    "[" + lit[:value].map {|v| to_s(v) }.join(", ") + "]"
  elsif lit[:type] == :object
    "{" + lit[:value].map {|v| to_s(v[:key]) + ": " + to_s(v[:value]) }.join(", ") + "}"
  else
    lit[:value]
  end
end