Method: HookApp#output_array

Defined in:
lib/hook/hookapp.rb

#output_array(hooks_arr, opts) ⇒ Object

Output an array of hooks in the given format.



521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
# File 'lib/hook/hookapp.rb', line 521

def output_array(hooks_arr, opts)
  if !hooks_arr.empty?
    hooks_arr.reject! { |h| h[:path].nil? || h[:path] == '' } if opts[:files_only]

    output = []

    case opts[:format]
    when /^m/
      hooks_arr.each do |h|
        if h[:name].empty?
          title = h[:url]
        else
          title = h[:name]
        end
        output.push("- [#{title}](#{h[:url]})")
      end
    when /^p/
      hooks_arr.each do |h|
        output.push(h[:path].nil? ? h[:url] : h[:path])
      end
    when /^h/
      hooks_arr.each do |h|
        output.push(h[:url])
      end
    else
      hooks_arr.each do |h|
        output.push("Title: #{h[:name]}\nPath: #{h[:path]}\nAddress: #{h[:url]}\n---------------------")
      end
    end
  else
    warn 'No bookmarks'
  end

  output
end