Class: ConvenientService::Utils::Array::Rjust

Inherits:
Support::Command show all
Defined in:
lib/convenient_service/utils/array/rjust.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Support::Command

[], call

Constructor Details

#initialize(array, size, pad = nil) ⇒ void

Parameters:

  • array (Array)
  • size (Integer)
  • pad (Object) (defaults to: nil)

    Can be any type.



36
37
38
39
40
# File 'lib/convenient_service/utils/array/rjust.rb', line 36

def initialize(array, size, pad = nil)
  @array = array
  @size = size
  @pad = pad
end

Instance Attribute Details

#arrayObject (readonly)

Returns the value of attribute array.



16
17
18
# File 'lib/convenient_service/utils/array/rjust.rb', line 16

def array
  @array
end

#padObject (readonly)

Returns the value of attribute pad.



28
29
30
# File 'lib/convenient_service/utils/array/rjust.rb', line 28

def pad
  @pad
end

#sizeObject (readonly)

Returns the value of attribute size.



22
23
24
# File 'lib/convenient_service/utils/array/rjust.rb', line 22

def size
  @size
end

Instance Method Details

#callArray

Returns:



45
46
47
48
49
50
51
# File 'lib/convenient_service/utils/array/rjust.rb', line 45

def call
  return array if size <= array.size

  count = size - array.size

  array + [pad] * count
end