Class: ConvenientService::Utils::String::Truncate Private
- Inherits:
-
Support::Command
- Object
- Support::Command
- ConvenientService::Utils::String::Truncate
- Defined in:
- lib/convenient_service/utils/string/truncate.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Attribute Summary collapse
- #omission ⇒ Object readonly private
- #string ⇒ Object readonly private
- #truncate_at ⇒ Object readonly private
Instance Method Summary collapse
- #call ⇒ String private
- #initialize(string, truncate_at, omission: "...") ⇒ void constructor private
Methods inherited from Support::Command
Constructor Details
#initialize(string, truncate_at, omission: "...") ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
53 54 55 56 57 |
# File 'lib/convenient_service/utils/string/truncate.rb', line 53 def initialize(string, truncate_at, omission: "...") @string = string.to_s @truncate_at = truncate_at @omission = omission end |
Instance Attribute Details
#omission ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
45 46 47 |
# File 'lib/convenient_service/utils/string/truncate.rb', line 45 def omission @omission end |
#string ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
33 34 35 |
# File 'lib/convenient_service/utils/string/truncate.rb', line 33 def string @string end |
#truncate_at ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
39 40 41 |
# File 'lib/convenient_service/utils/string/truncate.rb', line 39 def truncate_at @truncate_at end |
Instance Method Details
#call ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
62 63 64 65 66 67 68 69 70 |
# File 'lib/convenient_service/utils/string/truncate.rb', line 62 def call return "" if truncate_at <= 0 return string if truncate_at >= string.length return omission[...truncate_at] if truncate_at <= omission.length "#{string[...truncate_at - omission.length]}#{omission}" end |