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
48 49 50 51 52 |
# File 'lib/convenient_service/utils/string/truncate.rb', line 48 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.
40 41 42 |
# File 'lib/convenient_service/utils/string/truncate.rb', line 40 def omission @omission end |
#string ⇒ Object (readonly)
Returns the value of attribute string.
28 29 30 |
# File 'lib/convenient_service/utils/string/truncate.rb', line 28 def string @string end |
#truncate_at ⇒ Object (readonly)
Returns the value of attribute truncate_at.
34 35 36 |
# File 'lib/convenient_service/utils/string/truncate.rb', line 34 def truncate_at @truncate_at end |
Instance Method Details
#call ⇒ String
57 58 59 60 61 62 63 64 65 |
# File 'lib/convenient_service/utils/string/truncate.rb', line 57 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 |