class DigiMoji::String

Attributes

raw_string[R]
string[RW]

Public Class Methods

new(str, space:1, **opts) click to toggle source
# File lib/digi_moji.rb, line 11
def initialize(str, space:1, **opts)
  @raw_string = str.to_s
  @space = space
  @opts = opts
  @bg = opts[:bg]
  # @string holds a sequence of Char objects.
  @string = str2chars(str, opts)
end

Public Instance Methods

+(other, **opts) click to toggle source
# File lib/digi_moji.rb, line 26
def +(other, **opts)
  opts = @opts.merge(opts)
  other =
    case other
    when ::String, ::Symbol
      str2chars(other, opts)
    when DigiMoji::String
      other.string
    else
      raise "'other' should be a string, symbol or DigiString object."
    end
  self.dup.tap { |s| s.string += other }
end
Also aliased as: join
<<(other, **opts) click to toggle source
# File lib/digi_moji.rb, line 41
def <<(other, **opts)
  @string = (self + other).string
  @raw_string += other.respond_to?(:raw_string) ? other.raw_string : other.to_s
  self
end
join(other, **opts)
Alias for: +
to_s() click to toggle source
# File lib/digi_moji.rb, line 20
def to_s
  head, *rest = @string
  joint = (" " * @space).colco(@bg, regexp:/./)
  head.zip(*rest).map { |e| e.join(joint) }.join("\n")
end

Private Instance Methods

str2chars(str, opts) click to toggle source
# File lib/digi_moji.rb, line 48
def str2chars(str, opts)
  str.to_s.each_char.map { |chr| Char[chr.intern, opts] }
end