Class: GraphQLFormatter::LineOfCharacterStrings
- Inherits:
-
Object
- Object
- GraphQLFormatter::LineOfCharacterStrings
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/graphql-formatter/line_of_character_strings.rb
Instance Attribute Summary collapse
-
#indent_level ⇒ Object
Returns the value of attribute indent_level.
-
#strings ⇒ Object
readonly
Returns the value of attribute strings.
Instance Method Summary collapse
- #current_color ⇒ Object
- #current_string ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(indent_level: 0) ⇒ LineOfCharacterStrings
constructor
A new instance of LineOfCharacterStrings.
- #last_char ⇒ Object
- #new_string(color: nil, **opts) ⇒ Object
- #previous_string ⇒ Object
- #to_s(indenter: (' ' * 4), **opts) ⇒ Object
Constructor Details
#initialize(indent_level: 0) ⇒ LineOfCharacterStrings
Returns a new instance of LineOfCharacterStrings.
10 11 12 13 |
# 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 |
Instance Attribute Details
#indent_level ⇒ Object
Returns the value of attribute indent_level.
6 7 8 |
# File 'lib/graphql-formatter/line_of_character_strings.rb', line 6 def indent_level @indent_level end |
#strings ⇒ Object (readonly)
Returns the value of attribute strings.
5 6 7 |
# File 'lib/graphql-formatter/line_of_character_strings.rb', line 5 def strings @strings end |
Instance Method Details
#current_color ⇒ Object
39 40 41 |
# File 'lib/graphql-formatter/line_of_character_strings.rb', line 39 def current_color current_string.color end |
#current_string ⇒ Object
35 36 37 |
# File 'lib/graphql-formatter/line_of_character_strings.rb', line 35 def current_string @strings.last end |
#empty? ⇒ Boolean
43 44 45 |
# File 'lib/graphql-formatter/line_of_character_strings.rb', line 43 def empty? strings.all? &:empty? end |
#last_char ⇒ Object
26 27 28 29 |
# 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) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# 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 ⇒ Object
31 32 33 |
# File 'lib/graphql-formatter/line_of_character_strings.rb', line 31 def previous_string @strings[-2] end |
#to_s(indenter: (' ' * 4), **opts) ⇒ Object
47 48 49 50 |
# 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 |