class GraphQLFormatter::LineOfCharacterStrings
Attributes
indent_level[RW]
strings[R]
Public Class Methods
new(indent_level: 0)
click to toggle source
# File lib/graphql-formatter/line_of_character_strings.rb, line 10 def initialize(indent_level: 0) self.indent_level = indent_level @strings = [GraphQLFormatter::CharacterString.new] end
Public Instance Methods
current_color()
click to toggle source
# File lib/graphql-formatter/line_of_character_strings.rb, line 39 def current_color current_string.color end
current_string()
click to toggle source
# File lib/graphql-formatter/line_of_character_strings.rb, line 35 def current_string @strings.last end
empty?()
click to toggle source
# File lib/graphql-formatter/line_of_character_strings.rb, line 43 def empty? strings.all? &:empty? end
last_char()
click to toggle source
# File lib/graphql-formatter/line_of_character_strings.rb, line 26 def last_char (current_string && current_string.last_char) || (previous_string && previous_string.last_char) end
new_string(color: nil, **opts)
click to toggle source
# File lib/graphql-formatter/line_of_character_strings.rb, line 15 def new_string(color: nil, **opts) return current_string if color == current_color if current_string.empty? current_string.color = color return current_string end GraphQLFormatter::CharacterString.new(color: color, **opts).tap do |string| @strings << string end end
previous_string()
click to toggle source
# File lib/graphql-formatter/line_of_character_strings.rb, line 31 def previous_string @strings[-2] end
to_s(indenter: (' ' * 4), **opts)
click to toggle source
# File lib/graphql-formatter/line_of_character_strings.rb, line 47 def to_s(indenter: (' ' * 4), **opts) indent = indenter * indent_level indent + reject(&:empty?).map { |str| str.to_s(**opts) }.join end