Class: DigiMoji::String
- Inherits:
-
Object
- Object
- DigiMoji::String
- Defined in:
- lib/digi_moji.rb
Instance Attribute Summary collapse
-
#raw_string ⇒ Object
readonly
Returns the value of attribute raw_string.
-
#string ⇒ Object
Returns the value of attribute string.
Instance Method Summary collapse
- #+(other, **opts) ⇒ Object (also: #join)
- #<<(other, **opts) ⇒ Object
-
#initialize(str, space: 1, **opts) ⇒ String
constructor
A new instance of String.
- #to_s ⇒ Object
Constructor Details
#initialize(str, space: 1, **opts) ⇒ String
Returns a new instance of String.
11 12 13 14 15 16 17 18 |
# 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 |
Instance Attribute Details
#raw_string ⇒ Object (readonly)
Returns the value of attribute raw_string.
10 11 12 |
# File 'lib/digi_moji.rb', line 10 def raw_string @raw_string end |
#string ⇒ Object
Returns the value of attribute string.
9 10 11 |
# File 'lib/digi_moji.rb', line 9 def string @string end |
Instance Method Details
#+(other, **opts) ⇒ Object Also known as: join
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# 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 |
#<<(other, **opts) ⇒ Object
41 42 43 44 45 |
# 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 |
#to_s ⇒ Object
20 21 22 23 24 |
# 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 |