Skip to content

Opinionated UA formatsΒ #111

@AxelTheGerman

Description

@AxelTheGerman

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions