Module: WarclightHelper

Defined in:
app/helpers/warclight_helper.rb

Overview

Generic Helpers used in Warclight

Instance Method Summary collapse

Instance Method Details

#return_five(options = {}) ⇒ Object



19
20
21
22
23
24
25
# File 'app/helpers/warclight_helper.rb', line 19

def return_five(options = {})
  if options[:value].length > 5
    options[:value][0, 5].join('; ') + '...'
  else
    options[:value].join('; ')
  end
end


6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/helpers/warclight_helper.rb', line 6

def url_to_link(options = {})
  safe_join(options[:value].map do |url|
    res = Net::HTTP.get_response(URI(url))
    if res.code.start_with?('1', '2', '3')
      link_to(url, url, target: '_blank', rel: 'noopener') << ' 🔗'
    else
      url + ' (Not available)'
    end
  rescue
    url + ' (Not available)'
  end, '')
end