Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

attparser

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

attparser

  • 1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

AttParser

AttParser parses a string like you might find in an HTML tag. Optionally, it will convert certain values into other classes like Integer or TrueClass.

In its simplest use, give AttParser a string that is formatted like the attributes in HTML. Then run the string through AttParser.parse(). That method will return a hash.

raw = 'whatever="dude" ready YEAH=man'
atts = AttParser.parse(raw)
atts['whatever'] # => "dude"
atts['ready']    # => nil
atts['yeah']     # => "man"

The attribute names are downcased. Values quotes are returned as string. Values without spaces are returned as string. If an attribute does not have a value (i.e. there is no equals sign) then the value is nil.

Infer

If you add the infer option then certain values are inferred as objects other than strings. NOTE: Only unquoted strings are inferred, never quoted strings. Quoted strings are always returned as strings.

raw = 'my-false=false my-true=true my-int=-2 my-float=3.4 my-nil=nil'
atts = AttParser.parse(raw, 'infer'=>true)
atts['my-false'].class  # => FalseClass
atts['my-true'].class   # => TrueClass
atts['my-int'].class    # => Integer
atts['my-float'].class  # => Float
atts['my-nil'].class    # => NilClass

That's it

That's what AttParser does. If you want to get more complex, it's probably best to use JSON.

Install

gem install attparser

Author

Mike O'Sullivan mike@idocs.com

History

versiondatenotes
1.0June 18, 2020Initial upload.

FAQs

Package last updated on 18 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc