Class: ConvenientService::Utils::String::Truncate
- Inherits:
-
Support::Command
- Object
- Support::Command
- ConvenientService::Utils::String::Truncate
- Defined in:
- lib/convenient_service/utils/string/truncate.rb
Overview
Instance Attribute Summary collapse
-
#omission ⇒ Object
readonly
Returns the value of attribute omission.
-
#string ⇒ Object
readonly
Returns the value of attribute string.
-
#truncate_at ⇒ Object
readonly
Returns the value of attribute truncate_at.
Instance Method Summary collapse
Methods inherited from Support::Command
Constructor Details
#initialize(string, truncate_at, omission: "...") ⇒ void
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)
Returns the value of attribute omission.
45 46 47 |
# File 'lib/convenient_service/utils/string/truncate.rb', line 45 def omission @omission end |
#string ⇒ Object (readonly)
Returns the value of attribute string.
33 34 35 |
# File 'lib/convenient_service/utils/string/truncate.rb', line 33 def string @string end |
#truncate_at ⇒ Object (readonly)
Returns the value of attribute truncate_at.
39 40 41 |
# File 'lib/convenient_service/utils/string/truncate.rb', line 39 def truncate_at @truncate_at end |
Instance Method Details
#call ⇒ String
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 |