class HighLine::Statement
This class handles proper formatting based on a HighLine
context, applying wrapping, pagination, indentation and color rendering when necessary. It's used by {HighLine#render_statement} @see HighLine#render_statement
Attributes
highline[R]
The HighLine
context @return [HighLine]
source[R]
The source object to be stringfied and formatted.
template_string[R]
The stringfied source object @return [String]
Public Class Methods
const_missing(constant)
click to toggle source
# File lib/highline/statement.rb, line 48 def self.const_missing(constant) HighLine.const_get(constant) end
new(source, highline)
click to toggle source
Public Instance Methods
statement()
click to toggle source
Returns the formated statement. Applies wrapping, pagination, indentation and color rendering based on HighLine
instance settings. @return [String] formated statement
# File lib/highline/statement.rb, line 38 def statement @statement ||= format_statement end
to_s()
click to toggle source
(see statement
) Delegates to {#statement}
# File lib/highline/statement.rb, line 44 def to_s statement end
Private Instance Methods
format_statement()
click to toggle source
# File lib/highline/statement.rb, line 58 def format_statement return template_string if template_string.empty? statement = render_template statement = HighLine::Wrapper.wrap(statement, highline.wrap_at) statement = HighLine::Paginator.new(highline).page_print(statement) statement = statement.gsub(/\n(?!$)/, "\n#{highline.indentation}") if highline.multi_indent statement end
render_template()
click to toggle source
# File lib/highline/statement.rb, line 72 def render_template # Assigning to a local var so it may be # used inside instance eval block template_renderer = TemplateRenderer.new(template, source, highline) template_renderer.render end
stringfy(template_string)
click to toggle source
# File lib/highline/statement.rb, line 54 def stringfy(template_string) String(template_string || "").dup end
template()
click to toggle source
# File lib/highline/statement.rb, line 80 def template @template ||= if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+ ERB.new(template_string, trim_mode: "%") else ERB.new(template_string, nil, "%") end end