Class: JsonToGraphql::Parser::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/json_to_graphql/parser.rb

Constant Summary collapse

SPACES_PER_TAB =
2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, args:, attrs:) ⇒ Node



34
35
36
37
38
39
40
# File 'lib/json_to_graphql/parser.rb', line 34

def initialize(name:, args:, attrs:)
  @name = name
  @children = []
  @attrs = attrs || []
  @args = args || {}
  @variables = {}
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



31
32
33
# File 'lib/json_to_graphql/parser.rb', line 31

def args
  @args
end

#attrsObject

Returns the value of attribute attrs.



31
32
33
# File 'lib/json_to_graphql/parser.rb', line 31

def attrs
  @attrs
end

#childrenObject

Returns the value of attribute children.



31
32
33
# File 'lib/json_to_graphql/parser.rb', line 31

def children
  @children
end

#nameObject

Returns the value of attribute name.



31
32
33
# File 'lib/json_to_graphql/parser.rb', line 31

def name
  @name
end

#variablesObject

Returns the value of attribute variables.



31
32
33
# File 'lib/json_to_graphql/parser.rb', line 31

def variables
  @variables
end

Instance Method Details



42
43
44
45
46
47
48
49
# File 'lib/json_to_graphql/parser.rb', line 42

def print(string, level)
  indentation = " " * (level * SPACES_PER_TAB)
  next_level_indentation = " " * ((level.succ) * SPACES_PER_TAB)
  string.concat(indentation, "#{name}", arg_var_string, "{\n")
  attrs.each { |attr| string.concat(next_level_indentation, "#{attr}\n") }
  children.each { |child| child.print(string, level.succ) }
  string.concat(indentation, "}\n")
end