GithubHelp home page GithubHelp logo

oleander / rchardet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from edouard/rchardet

34.0 4.0 5.0 654 KB

Character encoding auto-detection. Ruby 1.9 compatible

Home Page: https://github.com/oleander/rchardet

License: GNU Lesser General Public License v2.1

Ruby 100.00%

rchardet's Introduction

rCharDet19

Project Page | 1.9 Author | Original Author

rCharDet is a character encoding detection library for ruby and the implementation is based on Mozilla Charset Detectors.

This is a forked project in a effort to make it Ruby 1.9 compatible.

Follow me on Twitter or Github for more info and updates.

How to use

CharDet.detect takes the variable data that contains an unknown encoding.

We then try to change the encoding to UTF-8, but only if we are at least ~ 60% sure that we found the right encoding.

data = "Some unknown data"
cd = CharDet.detect(data)
data = cd.confidence > 0.6 ? Iconv.conv(cd.encoding, "UTF-8", data) : data

What do I've to work with?

A struct is being returned from the detect method, it has the following accessors.

  • encoding (String) Encoding of the ingoing string, UTF-8 for example.
  • confidence (Float) The confidence level of the encoding, from 0.0 to 1.0, where 1.0 is the best.

Make it silent

The detect takes two arguments, the string to guess the encoding on and an option hash.

You can use the option hash de decide if you want the detect method to raise an exception or not if the ingoing string is nil.

CharDet.detect("some data", :silent => true) # Won't raise an exception
CharDet.detect(nil, :silent => true)         # Won't raise an exception
CharDet.detect(nil)                          # Will raise an exception
CharDet.detect(nil, :silent => false)        # Will raise an exception

How do install

[sudo] gem install rchardet19

How to use it in a rails 3 project

Add gem 'rchardet19' to your Gemfile and run bundle.

How to help

  • Start by copying the project or make your own branch.
  • Navigate to the root path of the project and run bundle.
  • Start by running all tests using rspec, rspec spec/rchardet19_spec.rb.
  • Implement your own code, write some tests, commit and do a pull request.

Requirements

rCharDet19 is tested in

  • OS X 10.6.6 using Ruby 1.8.7 and 1.9.2.
  • Ubuntu 12.10 using Ruby 1.9.3 and 2.0.0-p0

License

rCharDet19 is released under the MIT license.

rchardet's People

Contributors

edouard avatar jmhodges avatar mindbreaker avatar oleander avatar speedmax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.