Open allspiritseve opened 8 years ago
It can be useful in some situations to know when a user agent can't be parsed correctly. My preference is to return an empty string instead of Mozilla/4.0 (compatible)
. As not everyone has this preference, it makes sense to allow a configurable default rather than having to monkeypatch UserAgent::DEFAULT_USER_AGENT
.
I can see something along those lines being useful. For example, if returning nil
for a user agent that couldn't be detected you could do something like:
if ua = UserAgent.parse(user_agent)
# Something based on known UA
else
# Fallback for unknown UA
end
I could also see a parse!
variant that raised an error if the UA was unknown being useful for similar patterns.
WDYT? Yours is a non-breaking change but I'm already considering a major version for #40 so I could include a breaking change along these lines with that into a major version.
@gshutler sounds good to me!
What is the use case for this change?