Class: PushBuilder::StringCropper
- Inherits:
-
Object
- Object
- PushBuilder::StringCropper
- Defined in:
- lib/push_builder/string_cropper.rb
Constant Summary collapse
- DEFAULT_CROP_INDICATOR =
?…
Instance Attribute Summary collapse
-
#indicator ⇒ Object
readonly
Returns the value of attribute indicator.
-
#string ⇒ Object
readonly
Returns the value of attribute string.
Instance Method Summary collapse
- #crop_bytes(bytes_to_crop) ⇒ Object
-
#initialize(string, indicator = DEFAULT_CROP_INDICATOR) ⇒ StringCropper
constructor
A new instance of StringCropper.
Constructor Details
#initialize(string, indicator = DEFAULT_CROP_INDICATOR) ⇒ StringCropper
Returns a new instance of StringCropper.
9 10 11 12 |
# File 'lib/push_builder/string_cropper.rb', line 9 def initialize(string, indicator=DEFAULT_CROP_INDICATOR) @string = string @indicator = indicator end |
Instance Attribute Details
#indicator ⇒ Object (readonly)
Returns the value of attribute indicator.
7 8 9 |
# File 'lib/push_builder/string_cropper.rb', line 7 def indicator @indicator end |
#string ⇒ Object (readonly)
Returns the value of attribute string.
7 8 9 |
# File 'lib/push_builder/string_cropper.rb', line 7 def string @string end |
Instance Method Details
#crop_bytes(bytes_to_crop) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/push_builder/string_cropper.rb', line 14 def crop_bytes(bytes_to_crop) return string if bytes_to_crop <= 0 bytes_to_crop += indicator.bytesize remaining_bytes = string.bytesize - bytes_to_crop string_with_bytes(remaining_bytes) + indicator end |