https://github.com/codenoble/deranged
A natural language range parser with ActiveModel helpers
https://github.com/codenoble/deranged
Last synced: 8 months ago
JSON representation
A natural language range parser with ActiveModel helpers
- Host: GitHub
- URL: https://github.com/codenoble/deranged
- Owner: codenoble
- License: mit
- Created: 2016-05-30T12:46:18.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-05-30T15:11:10.000Z (about 10 years ago)
- Last Synced: 2025-10-02T09:54:43.045Z (9 months ago)
- Language: Ruby
- Size: 2.93 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: MIT-LICENSE
Awesome Lists containing this project
README
Deranged
========
A natural language range parser with ActiveModel helpers.
Installation
------------
Just add `gem 'deranged'` to your `Gemfile` and `bundle install` it.
Usage
-----
```ruby
Deranged.parse('2010-2016') #=> 2010..2016
Deranged.parse('1,000,000 to 1,000,000,000 dollars') #=> 1000000..1000000000
Deranged::Parser.new('between .42 and 42').to_range #=> 0.42..42.0
Deranged.format(1..10) #=> "1-10"
Deranged::Formatter.new(3..33.3333333).to_s #=> "3-33.3333333"
class JobOpportunity
include Deranged::Attrs
attr_accessor :salary_range
derange :salary_range
end
job = JobOpportunity.new
job.salary_range_string = '$75,000 - $85,000'
job.salary_range #=> 75000..85000
job.salary_range_string #=> "75000-85000"
```
TODO:
-----
- Tests
- Custom formatting