Module: Wco::ApplicationHelper

Included in:
ApplicationController
Defined in:
app/helpers/wco/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#my_truthy?(which) ⇒ Boolean



8
9
10
# File 'app/helpers/wco/application_helper.rb', line 8

def my_truthy? which
  ["1", "t", "T", "true"].include?( which )
end

#obfuscate(link) ⇒ Object



12
13
14
15
16
17
18
# File 'app/helpers/wco/application_helper.rb', line 12

def obfuscate link
  # puts! link, 'obfuscate helper' if DEBUG
  obf = WcoEmail::ObfuscatedRedirect.find_or_create_by({ to: link })
  return WcoEmail::Engine.routes.url_helpers.obf_url( obf.id, {
    host: Rails.application.routes.default_url_options[:host],
  })
end

#pexels_search_path(opts) ⇒ Object



4
5
6
# File 'app/helpers/wco/application_helper.rb', line 4

def pexels_search_path(opts)
  "/2025/pexels_example_169.html?pexels_api_key=#{PEXELS_API_KEY}&newsvideo_id=#{opts[:newsvideo_id]}"
end

#pp_amount(a, config = { precision: 2 }) ⇒ Object



36
37
38
39
40
41
# File 'app/helpers/wco/application_helper.rb', line 36

def pp_amount a, config = { precision: 2 }
  return '-' if !a
  return '-' if a.class == String
  return number_to_currency a, precision: config[:precision]
  # "$#{'%.2f' % a}"
end

#pp_currency(a) ⇒ Object



43
# File 'app/helpers/wco/application_helper.rb', line 43

def pp_currency a; pp_amount a; end

#pp_date(a) ⇒ Object



24
# File 'app/helpers/wco/application_helper.rb', line 24

def pp_date a; pretty_date a; end

#pp_datetime(date) ⇒ Object



26
27
28
29
# File 'app/helpers/wco/application_helper.rb', line 26

def pp_datetime date
  return nil if !date
  return date.in_time_zone( Rails.application.config.time_zone ).strftime('%Y-%m-%d %l:%M%P %Z')
end

#pp_money(a) ⇒ Object

“$#% a”



42
# File 'app/helpers/wco/application_helper.rb', line 42

def pp_money a; pp_amount a; end

#pp_percent(a, config = { precision: 2}) ⇒ Object



44
45
46
# File 'app/helpers/wco/application_helper.rb', line 44

def pp_percent a, config = { precision: 2}
  "#{(a*100).round( config[:precision] )}%" rescue '@TODO'
end

#pp_time(date) ⇒ Object



31
32
33
34
# File 'app/helpers/wco/application_helper.rb', line 31

def pp_time date
  return nil if !date
  return date.in_time_zone( Rails.application.config.time_zone ).strftime('%l:%M%P %Z')
end

#pretty_date(date) ⇒ Object



20
21
22
23
# File 'app/helpers/wco/application_helper.rb', line 20

def pretty_date date
  return nil if !date
  date.in_time_zone( Rails.application.config.time_zone ).strftime('%Y-%m-%d')
end