Class: RubyJard::Decorators::StringDecorator
- Inherits:
-
Object
- Object
- RubyJard::Decorators::StringDecorator
- Defined in:
- lib/ruby_jard/decorators/string_decorator.rb
Overview
A light decorator for a string. String should be escaped, and cut off.
Instance Method Summary collapse
-
#decorate_multiline(variable, first_line_limit:, line_limit:, lines:, depth: 0) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
- #decorate_singleline(variable, line_limit:, depth: 0) ⇒ Object
-
#initialize(generic_decorator) ⇒ StringDecorator
constructor
A new instance of StringDecorator.
- #match?(variable) ⇒ Boolean
Constructor Details
#initialize(generic_decorator) ⇒ StringDecorator
Returns a new instance of StringDecorator.
8 9 10 |
# File 'lib/ruby_jard/decorators/string_decorator.rb', line 8 def initialize(generic_decorator) @generic_decorator = generic_decorator end |
Instance Method Details
#decorate_multiline(variable, first_line_limit:, line_limit:, lines:, depth: 0) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
17 18 19 20 21 |
# File 'lib/ruby_jard/decorators/string_decorator.rb', line 17 def decorate_multiline(variable, first_line_limit:, line_limit:, lines:, depth: 0) [ decorate_singleline(variable, line_limit: first_line_limit) ] end |
#decorate_singleline(variable, line_limit:, depth: 0) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ruby_jard/decorators/string_decorator.rb', line 23 def decorate_singleline(variable, line_limit:, depth: 0) inspection = variable.inspect[1..-1].chomp!('"') str = if inspection.length < line_limit - 2 inspection else inspection[0..line_limit - 4] + '…' end [ RubyJard::Span.new(content: '"', styles: :string), RubyJard::Span.new(content: str, styles: :string), RubyJard::Span.new(content: '"', styles: :string) ] end |
#match?(variable) ⇒ Boolean
12 13 14 |
# File 'lib/ruby_jard/decorators/string_decorator.rb', line 12 def match?(variable) RubyJard::Reflection.call_is_a?(variable, String) end |