Class: GraphQLFormatter::LineCollection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/graphql-formatter/line_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLineCollection

Returns a new instance of LineCollection.



7
8
9
# File 'lib/graphql-formatter/line_collection.rb', line 7

def initialize
  @lines = [GraphQLFormatter::LineOfCharacterStrings.new]
end

Instance Attribute Details

#linesObject (readonly)

Returns the value of attribute lines.



5
6
7
# File 'lib/graphql-formatter/line_collection.rb', line 5

def lines
  @lines
end

Instance Method Details

#current_indent_levelObject



36
37
38
# File 'lib/graphql-formatter/line_collection.rb', line 36

def current_indent_level
  current_line.indent_level
end

#current_lineObject



14
15
16
# File 'lib/graphql-formatter/line_collection.rb', line 14

def current_line
  lines.last
end

#last_characterObject



40
41
42
43
# File 'lib/graphql-formatter/line_collection.rb', line 40

def last_character
  (current_line && current_line.last_char) ||
    (previous_line && previous_line.last_char)
end

#new_line(indent_level: current_indent_level, **opts) ⇒ Object



18
19
20
21
22
# File 'lib/graphql-formatter/line_collection.rb', line 18

def new_line(indent_level: current_indent_level, **opts)
  GraphQLFormatter::LineOfCharacterStrings.new(indent_level: indent_level, **opts).tap do |line|
    lines << line
  end
end

#new_string(**opts) ⇒ Object



24
25
26
# File 'lib/graphql-formatter/line_collection.rb', line 24

def new_string(**opts)
  current_line.new_string(**opts)
end

#previous_lineObject



28
29
30
# File 'lib/graphql-formatter/line_collection.rb', line 28

def previous_line
  lines[-2]
end

#previous_stringObject



32
33
34
# File 'lib/graphql-formatter/line_collection.rb', line 32

def previous_string
  current_line.previous_string || previous_line.current_string
end

#to_s(**opts) ⇒ Object



45
46
47
# File 'lib/graphql-formatter/line_collection.rb', line 45

def to_s(**opts)
  reject(&:empty?).map { |line| line.to_s(**opts) }.join("\n")
end