Class: Gitlab::Ci::Config::Interpolation::Functions::Truncate

Inherits:
Base
  • Object
show all
Defined in:
lib/gitlab/ci/config/interpolation/functions/truncate.rb

Instance Attribute Summary

Attributes inherited from Base

#errors

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize, matches?, #valid?

Constructor Details

This class inherits a constructor from Gitlab::Ci::Config::Interpolation::Functions::Base

Class Method Details

.function_expression_patternObject



9
10
11
# File 'lib/gitlab/ci/config/interpolation/functions/truncate.rb', line 9

def self.function_expression_pattern
  /^#{name}\(\s*(?<offset>\d+)\s*,\s*(?<length>\d+)\s*\)?$/
end

.nameObject



13
14
15
# File 'lib/gitlab/ci/config/interpolation/functions/truncate.rb', line 13

def self.name
  'truncate'
end

Instance Method Details

#execute(input_value) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/gitlab/ci/config/interpolation/functions/truncate.rb', line 17

def execute(input_value)
  if input_value.is_a?(String)
    input_value[offset, length].to_s
  else
    error('invalid input type: truncate can only be used with string inputs')
    nil
  end
end