Module: Ragabash::AwesomeStringFormatter
- Defined in:
- lib/ragabash/awesome_string_formatter.rb
Overview
Custom String formatter module for awesome_print
gem.
You can activate this automatically by including:
require "ragabash/ext/awesome_strings"
You can also activate this as part of an awesome_print-based Pry printer by including:
require "ragabash/ext/pry_awesome_print"
Class Method Summary collapse
-
.included(base) ⇒ Object
Intercept awesome_print type-cast method.
Instance Method Summary collapse
-
#awesome_string(string) ⇒ String
Format a String for awesome_print display.
-
#cast_with_string(object, type) ⇒ Boolean
Replacement type-cast method for awesome_print.
Class Method Details
.included(base) ⇒ Object
Intercept awesome_print type-cast method.
14 15 16 17 |
# File 'lib/ragabash/awesome_string_formatter.rb', line 14 def included(base) base.send :alias_method, :cast_without_string, :cast base.send :alias_method, :cast, :cast_with_string end |
Instance Method Details
#awesome_string(string) ⇒ String
Format a String for awesome_print display.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ragabash/awesome_string_formatter.rb', line 43 def awesome_string(string) lexers = ::Rouge::Guessers::Source.new(string).filter(R_LEXERS) if !lexers.empty? format_syntax_string(string, lexers.first) elsif string =~ /(?:\r?\n)(?!\z)/ format_multiline_string(string) else format_plain_string(string) end end |
#cast_with_string(object, type) ⇒ Boolean
Replacement type-cast method for awesome_print.
25 26 27 |
# File 'lib/ragabash/awesome_string_formatter.rb', line 25 def cast_with_string(object, type) object.is_a?(::String) ? :string : cast_without_string(object, type) end |