ageism 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +47 -0
- data/Rakefile +1 -0
- data/ageism.gemspec +22 -0
- data/lib/ageism.rb +23 -0
- data/lib/ageism/version.rb +3 -0
- data/spec/ageism_spec.rb +34 -0
- data/spec/spec_helper.rb +21 -0
- metadata +78 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 conanite
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Ageism
|
2
|
+
|
3
|
+
Quickly parse age intervals.
|
4
|
+
|
5
|
+
This gem was born of a need to allow teachers search for children by age, using an ultra-simple syntax and without
|
6
|
+
complicated and messy drop-down boxes. Given that teachers and admins are thinking in terms of age rather than date
|
7
|
+
of birth, it's important to provide a widget that speaks their language, so the system overall is more fluid and
|
8
|
+
intuitive to use.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'ageism'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install ageism
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
module ApplicationHelper # or wherever you plan to use this
|
27
|
+
include Ageism
|
28
|
+
|
29
|
+
...
|
30
|
+
min, max = parse_age_range params[:age_range]
|
31
|
+
|
32
|
+
### Examples
|
33
|
+
|
34
|
+
parse_age_range "12 - 13" # => [144, 156]
|
35
|
+
parse_age_range "0 6 - 1 6" # => [6, 18]
|
36
|
+
parse_age_range "0y 6m - 1y 6m" # => [6, 18]
|
37
|
+
parse_age_range "0 ans 6 mois - 1 an 6 mois" # => [6, 18]
|
38
|
+
parse_age_range "2 jahr - 3jahr" # => [24, 36]
|
39
|
+
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/ageism.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- coding: utf-8; mode: ruby -*-
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'ageism/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |gem|
|
8
|
+
gem.name = "ageism"
|
9
|
+
gem.version = Ageism::VERSION
|
10
|
+
gem.authors = ["conanite"]
|
11
|
+
gem.email = ["conan@conandalton.net"]
|
12
|
+
gem.description = %q{Given a string such as "4 - 5", "3y 6m - 4y 6m", return a hash with keys :left and :right whose values are each a number of months. Ageism splits on '-', discards all non-numeric characters, and expects either one or two integers on each side of the hyphen. One integer is a year; two integers are year and month. }
|
13
|
+
gem.summary = %q{Parse a pair of year-month values, returning 'left' and 'right' values as a number of months}
|
14
|
+
gem.homepage = "https://github.com/conanite/ageism"
|
15
|
+
|
16
|
+
gem.add_development_dependency 'rspec', '~> 2.9'
|
17
|
+
|
18
|
+
gem.files = `git ls-files`.split($/)
|
19
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
20
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
21
|
+
gem.require_paths = ["lib"]
|
22
|
+
end
|
data/lib/ageism.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "ageism/version"
|
2
|
+
|
3
|
+
module Ageism
|
4
|
+
|
5
|
+
def self._parse_single_age age
|
6
|
+
if age.match /[^\d]*(\d+)[^\d]+(\d+)[^\d]*/
|
7
|
+
years = $1.to_i
|
8
|
+
months = $2.to_i
|
9
|
+
elsif age.match /[^\d]*(\d+)[^\d]*/
|
10
|
+
years = $1.to_i
|
11
|
+
months = 0
|
12
|
+
else
|
13
|
+
return nil
|
14
|
+
end
|
15
|
+
|
16
|
+
(years * 12) + months
|
17
|
+
end
|
18
|
+
|
19
|
+
def parse_age_range age
|
20
|
+
range = age.split('-').map { |a| Ageism._parse_single_age a }.compact
|
21
|
+
range.size == 0 ? nil : range
|
22
|
+
end
|
23
|
+
end
|
data/spec/ageism_spec.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.expand_path('../spec_helper', __FILE__)
|
4
|
+
|
5
|
+
describe Ageism do
|
6
|
+
class Thing; include Ageism; end
|
7
|
+
|
8
|
+
let(:helper) { Thing.new }
|
9
|
+
|
10
|
+
it "should return [144, 156] for '12 - 13'" do
|
11
|
+
helper.parse_age_range("12 - 13").should == [144, 156]
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return [6, 18] for ' 0 6 - 1 6 '" do
|
15
|
+
helper.parse_age_range(" 0 6 - 1 6 ").should == [6, 18]
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should return [6, 18] for ' 0y 6m - 1y 6m'" do
|
19
|
+
helper.parse_age_range(" 0y 6m - 1y 6m").should == [6, 18]
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return [6, 18] for '0 ans 6 mois - 1an 6mois '" do
|
23
|
+
helper.parse_age_range("0 ans 6 mois - 1an 6mois ").should == [6, 18]
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return [24, 36] for '2 jahr - 3jahr'" do
|
27
|
+
helper.parse_age_range("2 jahr - 3jahr").should == [24, 36]
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should return nil for unparseable content" do
|
31
|
+
helper.parse_age_range("hello world").should be_nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
18
|
+
|
19
|
+
require "ageism"
|
20
|
+
|
21
|
+
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ageism
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- conanite
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.9'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.9'
|
30
|
+
description: ! 'Given a string such as "4 - 5", "3y 6m - 4y 6m", return a hash with
|
31
|
+
keys :left and :right whose values are each a number of months. Ageism splits on
|
32
|
+
''-'', discards all non-numeric characters, and expects either one or two integers
|
33
|
+
on each side of the hyphen. One integer is a year; two integers are year and month. '
|
34
|
+
email:
|
35
|
+
- conan@conandalton.net
|
36
|
+
executables: []
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- .gitignore
|
41
|
+
- .rspec
|
42
|
+
- Gemfile
|
43
|
+
- LICENSE.txt
|
44
|
+
- README.md
|
45
|
+
- Rakefile
|
46
|
+
- ageism.gemspec
|
47
|
+
- lib/ageism.rb
|
48
|
+
- lib/ageism/version.rb
|
49
|
+
- spec/ageism_spec.rb
|
50
|
+
- spec/spec_helper.rb
|
51
|
+
homepage: https://github.com/conanite/ageism
|
52
|
+
licenses: []
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.8.24
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Parse a pair of year-month values, returning 'left' and 'right' values as
|
75
|
+
a number of months
|
76
|
+
test_files:
|
77
|
+
- spec/ageism_spec.rb
|
78
|
+
- spec/spec_helper.rb
|