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

Opinionated UA formats #111

Open
AxelTheGerman opened this issue Oct 19, 2023 · 0 comments
Open

Opinionated UA formats #111

AxelTheGerman opened this issue Oct 19, 2023 · 0 comments

Comments

@AxelTheGerman
Copy link

Great gem, one thing I had to do immediately was to build my own display format.

user_agent = UserAgentParser.parse 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0;)'
=> #<UserAgentParser::UserAgent IE 9.0 (Windows Vista)>
user_agent.to_s
=> "IE 9.0"

As per above (from the docs) to_s is too brief for my liking - I actually prefer the inspect formatting.

Wondering if we should add a to_fs method or similar that maybe even has a couple of supported formats (inspired by Rails formatting of dates and times) e.g.

user_agent = UserAgentParser.parse "Mozilla/5.0 (Linux; Android 7.0; SAMSUNG SM-G930T Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/5.0 Chrome/51.0.2704.106 Mobile Safari/537.36"
=> #<UserAgentParser::UserAgent Samsung Internet 5.0 (Android 7.0) (Samsung SM-G930T)>
user_agent.to_fs
=> "Samsung Internet 5.0 (Android 7.0)"
user_agent.to_fs(:short)
=> "Samsung Internet 5.0"
user_agent.to_fs(:medium)
=> "Samsung Internet 5.0 (Android 7.0)"
user_agent.to_fs(:long)
=> "Samsung Internet 5.0 (Android 7.0) (Samsung SM-G930T)"

Open to different format suggestions.

Another option would be similar to timestamp formatting "YYYY-MM-DD HH:MM:SS Z" where we had a formatting string such as "F V (O) (D)" but that seems more confusing than helpful and doesn't deal well with optionally present information.

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

No branches or pull requests

1 participant