Sha256: d037553d10b58473ef052ed2a39863686cffb72bbea0fc4b31a72d9c2a65bb60

Contents?: true

Size: 640 Bytes

Versions: 6

Compression:

Stored size: 640 Bytes

Contents

# frozen_string_literal: true

##
# Generic Helpers used in Warclight
module WarclightHelper
  def url_to_link(options = {})
    safe_join(options[:value].map do |url|
      begin
        res = Net::HTTP.get_response(URI(url))
        if res.code.start_with?('1', '2', '3')
          link_to(url, url, target: '_blank') << ' 🔗'
        else
          url + ' (Not available)'
        end
      rescue
        url + ' (Not available)'
      end
    end, '')
  end

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
warclight-0.7.1 app/helpers/warclight_helper.rb
warclight-0.7.0 app/helpers/warclight_helper.rb
warclight-0.6.3 app/helpers/warclight_helper.rb
warclight-0.6.2 app/helpers/warclight_helper.rb
warclight-0.6.1 app/helpers/warclight_helper.rb
warclight-0.6.0 app/helpers/warclight_helper.rb