Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Text normalizer] Description could an object, not a string #175

Closed
wants to merge 1 commit into from

Conversation

thebravoman
Copy link

I have another object from another gem that is called @page_description and it is not a string. It is an active record. So could we call description.to_str and thus allow other objects to be passed.

@kpumuk
Copy link
Owner

kpumuk commented Nov 15, 2018

I like the idea. My main concern is that if you send an object by accident, it will throw a confusing error like:

NoMethodError: undefined method `to_str' for #<User:0x00007fda326480e8>

What do you think about moving this change to cleanup_string method, and also adding a validation? Like

    def cleanup_string(string)
      raise ArgumentError, 'Expected a string or an object that implements #to_str' unless string.respond_to?(:to_str)
      strip_tags(string.to_str).gsub(/\s+/, ' ').strip.html_safe
    end

@kpumuk
Copy link
Owner

kpumuk commented Nov 16, 2018

Merged within #183

@kpumuk kpumuk closed this Nov 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants