Class: GraphQLFormatter::LineCollection
- Inherits:
-
Object
- Object
- GraphQLFormatter::LineCollection
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/graphql-formatter/line_collection.rb
Instance Attribute Summary collapse
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
Instance Method Summary collapse
- #current_indent_level ⇒ Object
- #current_line ⇒ Object
-
#initialize ⇒ LineCollection
constructor
A new instance of LineCollection.
- #last_character ⇒ Object
- #new_line(indent_level: current_indent_level, **opts) ⇒ Object
- #new_string(**opts) ⇒ Object
- #previous_line ⇒ Object
- #previous_string ⇒ Object
- #to_s(**opts) ⇒ Object
Constructor Details
#initialize ⇒ LineCollection
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
#lines ⇒ Object (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_level ⇒ Object
36 37 38 |
# File 'lib/graphql-formatter/line_collection.rb', line 36 def current_indent_level current_line.indent_level end |
#current_line ⇒ Object
14 15 16 |
# File 'lib/graphql-formatter/line_collection.rb', line 14 def current_line lines.last end |
#last_character ⇒ Object
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_line ⇒ Object
28 29 30 |
# File 'lib/graphql-formatter/line_collection.rb', line 28 def previous_line lines[-2] end |
#previous_string ⇒ Object
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 |