apeiros / literal_parser

Parse Strings containing ruby literals and return a proper ruby object.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

README

Summary

Parse Strings containing ruby literals and return a proper ruby object.

Features

  • Recognizes about all Ruby literals: nil, true, false, Symbols, Integers, Floats, Hashes, Arrays
  • Additionally parses Constants, Dates and Times
  • Very easy to use

Installation

gem install literal_parser

Usage

A couple of examples:

LiteralParser.parse("nil") # => nil
LiteralParser.parse(":foo") # => :foo
LiteralParser.parse("123") # => 123
LiteralParser.parse("1.5") # => 1.5
LiteralParser.parse("1.5", use_big_decimal: true) # => #<BigDecimal:…,'0.15E1',18(18)>
LiteralParser.parse("[1, 2, 3]") # => [1, 2, 3]
LiteralParser.parse("{:a => 1, :b => 2}") # => {:a => 1, :b => 2}

Links

License

You can use this code under the {file:LICENSE.txt BSD-2-Clause License}, free of charge. If you need a different license, please ask the author.

About

Parse Strings containing ruby literals and return a proper ruby object.

License:BSD 2-Clause "Simplified" License


Languages

Language:CSS 42.7%Language:Ruby 35.3%Language:JavaScript 22.0%