Module: Crm::ReviewsIoHelper

Defined in:
app/helpers/crm/reviews_io_helper.rb

Instance Method Summary collapse

Instance Method Details

#auto_extracted_headline(comments) ⇒ Object

First sentence or first 12 words from stripped review HTML — matches review card display logic.



30
31
32
33
34
# File 'app/helpers/crm/reviews_io_helper.rb', line 30

def auto_extracted_headline(comments)
  body = ActionController::Base.helpers.strip_tags(comments.to_s)
  match = body.match(/\A(.+?[.!?])(?:\s|$)/)
  match ? match[1] : body.split.first(12).join(' ')
end

#rating_badge_class(rating) ⇒ String

Returns the appropriate Bootstrap badge class for a review rating

Parameters:

  • rating (Integer)

    The rating value (1-5)

Returns:

  • (String)

    The Bootstrap badge class



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

def rating_badge_class(rating)
  case rating.to_i
  when 5 then 'bg-success'
  when 4 then 'bg-primary'
  when 3 then 'bg-warning text-dark'
  when 2 then 'bg-orange'
  when 1 then 'bg-danger'
  else 'bg-secondary'
  end
end

#safe_external_url(url) ⇒ Object

Validates an external URL and returns it only if it uses http/https.
Returns '#' for invalid or non-http(s) URLs to prevent injection.



20
21
22
23
24
25
26
27
# File 'app/helpers/crm/reviews_io_helper.rb', line 20

def safe_external_url(url)
  return '#' if url.blank?

  uri = URI.parse(url)
  %w[http https].include?(uri.scheme) && uri.host.present? ? url : '#'
rescue URI::InvalidURIError
  '#'
end