Class: PushBuilder::StringCropper

Inherits:
Object
  • Object
show all
Defined in:
lib/push_builder/string_cropper.rb

Constant Summary collapse

DEFAULT_CROP_INDICATOR =
?…

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#indicatorObject (readonly)

Returns the value of attribute indicator.



7
8
9
# File 'lib/push_builder/string_cropper.rb', line 7

def indicator
  @indicator
end

#stringObject (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