class JsonToGraphql::Parser::Node
Constants
- SPACES_PER_TAB
Attributes
args[RW]
attrs[RW]
children[RW]
name[RW]
variables[RW]
Public Class Methods
new(name:, args:, attrs:)
click to toggle source
# File lib/json_to_graphql/parser.rb, line 34 def initialize(name:, args:, attrs:) @name = name @children = [] @attrs = attrs || [] @args = args || {} @variables = {} end
Public Instance Methods
print(string, level)
click to toggle source
# 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
Private Instance Methods
arg_var_string()
click to toggle source
# File lib/json_to_graphql/parser.rb, line 53 def arg_var_string if !args.empty? '(' + args.map{|k,v| "#{k}: #{v}"}.join(',') + ') ' elsif !variables.empty? '(' + variables.map{|k,v| "$#{k}: #{v}"}.join(',') + ') ' else "" end end