<commit_before># ruby-marshal

[![Hackage](https://img.shields.io/hackage/v/ruby-marshal.svg)](https://hackage.haskell.org/package/ruby-marshal)
[![Build Status][Build Status Image]][Build Status]
[Build Status Image]: https://travis-ci.org/filib/ruby-marshal.svg?branch=master
[Build Status]: https://travis-ci.org/filib/ruby-marshal

Haskell library to parse a subset of Ruby objects serialised with Marshal.dump.

## Supported Types

- `NilClass`
- `TrueClass | FalseClass`
- `Array`
- `Fixnum`
- `Float`
- `Hash`
- `String`
- `Symbol`

If you would like to add support for another type, please feel free to
create an issue or open a pull request using the guidelines below.

## Usage

### Example

``` haskell
{-# LANGUAGE OverloadedStrings #-}

module Main where

import Data.Monoid       (mconcat)
import Data.Ruby.Marshal (decode, RubyObject(..))
import System.Directory  (getCurrentDirectory)

import qualified Data.ByteString as BS
import qualified Data.Map.Strict as DM

key :: RubyObject
key = RIVar (RString "user_id", "UTF-8")

lookupId :: RubyObject -> Maybe RubyObject
lookupId (RHash cookie) = DM.lookup key cookie
lookupId _              = Nothing

main :: IO ()
main = do
  dir <- getCurrentDirectory
  rbs <- BS.readFile (mconcat [dir, "/test/bin/railsCookie.bin"])
  print $ case decode rbs of
    Just cookie -> lookupId cookie
    Nothing     -> Nothing
```

## Contributing<commit_msg>update readme with new example.<commit_after># ruby-marshal

[![Hackage](https://img.shields.io/hackage/v/ruby-marshal.svg)](https://hackage.haskell.org/package/ruby-marshal)
[![Build Status][Build Status Image]][Build Status]
[Build Status Image]: https://travis-ci.org/filib/ruby-marshal.svg?branch=master
[Build Status]: https://travis-ci.org/filib/ruby-marshal

Haskell library to parse a subset of Ruby objects serialised with Marshal.dump.

## Supported Types

- `NilClass`
- `TrueClass | FalseClass`
- `Array`
- `Fixnum`
- `Float`
- `Hash`
- `String`
- `Symbol`

If you would like to add support for another type, please feel free to
create an issue or open a pull request using the guidelines below.

## Usage

### Example

``` haskell
{-# LANGUAGE OverloadedStrings #-}

module Main where

import Data.Ruby.Marshal
import System.Directory  (getCurrentDirectory)

import qualified Data.ByteString as BS
import qualified Data.Map.Strict as DM

lookupUserID :: IVar -> RubyObject -> Maybe IVar
lookupUserID key hash = fromRuby hash >>= \map' ->
  DM.lookup key map'

main :: IO ()
main = do
  dir <- getCurrentDirectory
  rbs <- BS.readFile (mconcat [dir, "/test/bin/railsCookie.bin"])
  print $ case decode rbs of
    Just cookie -> lookupUserID ("user_id", UTF_8) cookie
    Nothing     -> Nothing
```

## Contributing
{'fraction_non_alphanumeric': 0.12874908558888076, 'fraction_numerical': 0.000731528895391368, 'mean_word_length': 4.009157509157509, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1606595', 'n_tokens_mistral': 908, 'n_tokens_neox': 862, 'n_words': 263}