Class: WhirledPeas::Utils::FormattedString
- Inherits:
-
Object
- Object
- WhirledPeas::Utils::FormattedString
- Defined in:
- lib/whirled_peas/utils/formatted_string.rb
Instance Attribute Summary collapse
-
#formatting ⇒ Object
readonly
Returns the value of attribute formatting.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #blank? ⇒ Boolean
- #each_char(&block) ⇒ Object
- #hash ⇒ Object
-
#initialize(raw, formatting = nil) ⇒ FormattedString
constructor
A new instance of FormattedString.
- #inspect ⇒ Object
- #length ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(raw, formatting = nil) ⇒ FormattedString
Returns a new instance of FormattedString.
12 13 14 15 |
# File 'lib/whirled_peas/utils/formatted_string.rb', line 12 def initialize(raw, formatting=nil) @raw = raw @formatting = [*formatting] end |
Instance Attribute Details
#formatting ⇒ Object (readonly)
Returns the value of attribute formatting.
10 11 12 |
# File 'lib/whirled_peas/utils/formatted_string.rb', line 10 def formatting @formatting end |
Class Method Details
.blank ⇒ Object
6 7 8 |
# File 'lib/whirled_peas/utils/formatted_string.rb', line 6 def self.blank new('') end |
Instance Method Details
#==(other) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/whirled_peas/utils/formatted_string.rb', line 33 def ==(other) case other when self.class hash == other.hash when String formatting.empty? && raw == other else false end end |
#blank? ⇒ Boolean
25 26 27 |
# File 'lib/whirled_peas/utils/formatted_string.rb', line 25 def blank? raw.empty? end |
#each_char(&block) ⇒ Object
21 22 23 |
# File 'lib/whirled_peas/utils/formatted_string.rb', line 21 def each_char(&block) raw.chars.each(&block) end |
#hash ⇒ Object
29 30 31 |
# File 'lib/whirled_peas/utils/formatted_string.rb', line 29 def hash [raw, formatting].hash end |
#inspect ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/whirled_peas/utils/formatted_string.rb', line 53 def inspect if raw.empty? || formatting.length == 0 raw.inspect else "<#{formatting.join(', ')}>#{raw}<0>".inspect end end |
#length ⇒ Object
17 18 19 |
# File 'lib/whirled_peas/utils/formatted_string.rb', line 17 def length raw.length end |