Coder Social home page Coder Social logo

gateguru / chronic_distance Goto Github PK

View Code? Open in Web Editor NEW

This project forked from olauzon/chronic_distance

0.0 4.0 0.0 105 KB

A simple Ruby natural language parser for distances.

Home Page: http://github.com/olauzon/chronic_distance

License: MIT License

Ruby 100.00%

chronic_distance's Introduction

Chronic Distance

A simple Ruby natural language parser for distances. Given a parse-able string distance, it returns the distance in millimeters.

The reverse can also be accomplished with the output method. Given a distance in millimeters, it outputs a string like “4 kilometers” or “4km” depending on the desired format.

Installation

$ gem install chronic_distance

Usage

>> require 'chronic_distance'
=> true

Parsing examples

>> ChronicDistance.parse('5 kilometers')
=> 5000000

>> ChronicDistance.parse('4 miles')
=> 6437376

>> ChronicDistance.parse('four miles')
=> 6437376

>> ChronicDistance.parse('1000m')
=> 1000000

>> ChronicDistance.parse('1000 meters')
=> 1000000

>> ChronicDistance.parse('ten yards')
=> 9144.0

>> ChronicDistance.parse('500 feet')
=> 152400.0

Nil is returned if the string can’t be parsed:

>> ChronicDistance.parse('kilometers')
=> nil

Output examples

>> ChronicDistance.output(5000000)
=> 5000000 mm

>> ChronicDistance.output(5000000, :format => :short, :unit => 'kilometers')
=> 5km

>> ChronicDistance.output(5000000, :format => :long, :unit => 'kilometers')
=> 5 kilometers

>> ChronicDistance.output(5000000, :unit => 'meters')
=> 5000 m

>> ChronicDistance.output(5000000, :format => :long, :unit => 'miles')
=> 3.10685596118667 miles

Inspiration

ChronicDistance borrows heavily from:

TODO

  • Benchmark, optimize

  • Other locale support

Copyright © 2009 Olivier Lauzon. See MIT-LICENSE for details.

chronic_distance's People

Contributors

olauzon 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.