Module: Atlassian::Util::TextUtil

Defined in:
lib/atlassian/util/text_util.rb

Instance Method Summary collapse

Instance Method Details

#convert_branch_name_to_sentence(branch_name) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/atlassian/util/text_util.rb', line 5

def convert_branch_name_to_sentence(branch_name)
  return '' if branch_name.nil?

  branch_name = branch_name.to_s
  return '' if branch_name.empty?

  issue_key_regex = /([A-Z]{1,10}-\d+)/
  branch_components = branch_name.split(issue_key_regex);

  parts = branch_components.each_with_index.map { |value, index|
    (index % 2 === 0) ? value.gsub(/[\-_]/, ' ') : value
  }

  to_sentence_case(parts.join(''))
end

#to_sentence_case(str) ⇒ Object


21
22
23
24
25
26
27
28
# File 'lib/atlassian/util/text_util.rb', line 21

def to_sentence_case(str)
  return '' if str.nil?

  str = str.to_s
  return '' if str.empty?

  str.slice(0, 1).upcase + str.slice(1, str.length)
end