Class: OneApm::Support::RenameRulesEngine::Rename::Segment
- Defined in:
- lib/one_apm/support/rename_rules_engine/rename/segment.rb
Constant Summary collapse
- OA_RENAME_SEM_FIRST_MARK =
'first_'.freeze
- OA_RENAME_SEM_LAST_MARK =
'last_'.freeze
- OA_RENAME_SEM_VALUE_SEPARATOR =
','.freeze
- OA_RENAME_SEM_REGEX =
/\d+,*/
- OA_RENAME_SEPARATOR =
'/'.freeze
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from OneApm::Support::RenameRulesEngine::Rename::Base
Instance Method Details
#segment(request) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/one_apm/support/rename_rules_engine/rename/segment.rb', line 15 def segment(request) return '' if !state || value.nil? separated_path = request.uri.path.split(OA_RENAME_SEPARATOR) separated_path.delete('') if value.start_with?(OA_RENAME_SEM_FIRST_MARK) to = (value.gsub(OA_RENAME_SEM_FIRST_MARK,'').to_i - 1) separated_path[0..to].join(OA_RENAME_SEPARATOR) elsif value.start_with?(OA_RENAME_SEM_LAST_MARK) from = (value.gsub(OA_RENAME_SEM_LAST_MARK,'').to_i) from = separated_path.size if from > separated_path.size from = -from separated_path[from..-1].join(OA_RENAME_SEPARATOR) elsif OA_RENAME_SEM_REGEX.match(value) value_at = value.split(OA_RENAME_SEM_VALUE_SEPARATOR) value_at.map{|at| separated_path.at(at.to_i-1)}.join(OA_RENAME_SEPARATOR) end end |