Module: Txgh::Utils
Instance Method Summary collapse
- #absolute_branch(branch) ⇒ Object
- #branches_equal?(first, second) ⇒ Boolean
-
#index_on(key, arr) ⇒ Object
Builds a hash from an array of hashes using a common key present in all the elements.
- #is_tag?(ref) ⇒ Boolean
- #slugify(str) ⇒ Object
Instance Method Details
#absolute_branch(branch) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/txgh/utils.rb', line 7 def absolute_branch(branch) return unless branch if is_tag?(branch) branch elsif branch.include?('heads/') branch else "heads/#{branch}" end end |
#branches_equal?(first, second) ⇒ Boolean
18 19 20 |
# File 'lib/txgh/utils.rb', line 18 def branches_equal?(first, second) absolute_branch(first) == absolute_branch(second) end |
#index_on(key, arr) ⇒ Object
Builds a hash from an array of hashes using a common key present in all the elements. For example, consider this array of hashes:
arr = [
{ 'param1' => 'dogs', 'param2' => 'hairy' },
{ 'param1' => 'cats', 'param2' => 'fuzzy' }
]
calling index_on(‘param1’, arr) returns:
{
'dogs' => { 'param1' => 'dogs', 'param2' => 'hairy' },
'cats' => { 'param1' => 'cats', 'param2' => 'fuzzy' }
}
40 41 42 43 44 |
# File 'lib/txgh/utils.rb', line 40 def index_on(key, arr) arr.each_with_object({}) do |hash, ret| ret[hash[key]] = hash end end |
#is_tag?(ref) ⇒ Boolean
22 23 24 |
# File 'lib/txgh/utils.rb', line 22 def is_tag?(ref) ref.include?('tags/') end |
#slugify(str) ⇒ Object
3 4 5 |
# File 'lib/txgh/utils.rb', line 3 def slugify(str) str.gsub('/', '_') end |