pluralize_no_count_if_one 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 45d73e77b5a8acbb56fa3d2f6fc59b2459e3b356
4
+ data.tar.gz: 36dfb12b73a695f61eb29a5732c631c9b9bf88d9
5
+ SHA512:
6
+ metadata.gz: 25576fc287222750a1fe49cefb378d72f45bf143946dcf93576556540f0f7068215f745cca8f247eecb231634089ba96e761b0b56969420f6f4e43bd3642f862
7
+ data.tar.gz: ace60c3355ab5eeb93ce371eaed74e8ab0b697e4d3b6cabe804f811a8726d6f7eb5c68a9cf331429dd61c08893f5ebec1722c0cf82d005cd1966de130eb14fdc
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1 @@
1
+ alone for github
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format nested
@@ -0,0 +1 @@
1
+ pluralize_no_count_if_one
@@ -0,0 +1 @@
1
+ ruby
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pluralize_no_count_if_one.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Guillaume Hain
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 zedtux
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.
@@ -0,0 +1,48 @@
1
+ # PluralizeNoCountIfOne
2
+
3
+ [![Build Status](https://travis-ci.org/zedtux/pluralize_no_count_if_one.png?branch=master)](https://travis-ci.org/zedtux/pluralize_no_count_if_one)
4
+
5
+ Add the missing `:no_count_if_one` option to the Rails [pluralize helper](http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#method-i-pluralize)
6
+
7
+ In the case you set the new option `:no_count_if_one` to true and the collection has only one value it will not show the count.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'pluralize_no_count_if_one'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install pluralize_no_count_if_one
22
+
23
+ ## Usage
24
+
25
+ = pluralize(0, "dependency", nil, no_count_if_one: true)
26
+ #=> 0 dependencies
27
+ = pluralize(1, "dependency", nil, no_count_if_one: true)
28
+ #=> dependency
29
+ = pluralize(1, "dependency", nil, no_count_if_one: false)
30
+ #=> 1 dependency
31
+ = pluralize(15, "dependency", nil, no_count_if_one: true)
32
+ #=> 15 dependencies
33
+
34
+ I'm using this gem for my [brewformulas.org](https://github.com/zedtux/brewformulas.org) project in order to show the following sentence:
35
+
36
+ * In the case the formula has only one dependency:
37
+ > The following dependency will be installed if you install Abcl:
38
+
39
+ * In the case the formula has multiple dependencies:
40
+ > The following 7 dependencies will be installed if you install Abcde:
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
@@ -0,0 +1,3 @@
1
+ require "pluralize_no_count_if_one/version"
2
+ require "pluralize_no_count_if_one/action_view/helpers"
3
+ require "pluralize_no_count_if_one/railtie" if defined?(Rails)
@@ -0,0 +1,39 @@
1
+ module PluralizeNoCountIfOne
2
+ module ActionView
3
+ module Helpers
4
+ # Attempts to pluralize the +singular+ word unless +count+ is 1. If
5
+ # +plural+ is supplied, it will use that when count is > 1, otherwise
6
+ # it will use the Inflector to determine the plural form.
7
+ #
8
+ # pluralize(1, 'person')
9
+ # # => 1 person
10
+ #
11
+ # pluralize(2, 'person')
12
+ # # => 2 people
13
+ #
14
+ # pluralize(3, 'person', 'users')
15
+ # # => 3 users
16
+ #
17
+ # pluralize(0, 'person')
18
+ # # => 0 people
19
+ #
20
+ # pluralize(0, 'person', nil, no_count_if_one: true)
21
+ # # => 0 people
22
+ #
23
+ # pluralize(1, 'person', nil, no_count_if_one: true)
24
+ # # => person
25
+ def pluralize(count, singular, plural = nil, options={no_count_if_one: false})
26
+ word = if (count == 1 || count =~ /^1(\.0+)?$/)
27
+ singular
28
+ else
29
+ plural || singular.pluralize
30
+ end
31
+
32
+ count ||= 0
33
+ count = nil if options[:no_count_if_one] && count == 1
34
+
35
+ "#{count} #{word}".strip
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,9 @@
1
+ module PluralizeNoCountIfOne
2
+ class Railtie < ::Rails::Railtie
3
+ initializer "pluralize_no_count_if_one.configure_view_controller" do |app|
4
+ ActiveSupport.on_load :action_view do
5
+ include PluralizeNoCountIfOne::ActionView::Helpers
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module PluralizeNoCountIfOne
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pluralize_no_count_if_one/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pluralize_no_count_if_one"
8
+ spec.version = PluralizeNoCountIfOne::VERSION
9
+ spec.authors = ["zedtux"]
10
+ spec.email = ["zedtux@zedroot.org"]
11
+ spec.description = %q{Add the missing :no_count_if_one option to the Rails pluralize helper}
12
+ spec.summary = %q{In the case you set the new option :no_count_if_one to true and the collection has only one value it will not show the count.}
13
+ spec.homepage = "https://github.com/zedtux/pluralize_no_count_if_one"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "railties"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "simplecov"
27
+ spec.add_development_dependency "rails"
28
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+ require "simplecov"
3
+ SimpleCov.start
4
+
5
+ ROOT_PATH = File.join(File.dirname(__FILE__), '..')
6
+ $:.unshift ROOT_PATH unless $:.include? ROOT_PATH
7
+
8
+ require "rubygems"
9
+ require "rspec"
10
+ require "rails"
11
+
12
+ require "lib/pluralize_no_count_if_one"
13
+
14
+ RSpec.configure do |config|
15
+ config.include PluralizeNoCountIfOne::ActionView::Helpers
16
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe PluralizeNoCountIfOne::ActionView::Helpers do
4
+ describe "#pluralize" do
5
+ context "passing a count of 0" do
6
+ context "without the :no_count_if_one option" do
7
+ it "should return \"0 people\"" do
8
+ pluralize(0, "person").should == "0 people"
9
+ end
10
+ end
11
+ context "with the :no_count_if_one option to false" do
12
+ it "should return \"0 people\"" do
13
+ pluralize(0, "person", nil, no_count_if_one: false).should == "0 people"
14
+ end
15
+ end
16
+ context "with the :no_count_if_one option to true" do
17
+ it "should return \"0 person\"" do
18
+ pluralize(0, "person", nil, no_count_if_one: true).should == "0 people"
19
+ end
20
+ end
21
+ end
22
+ context "passing a count of 1" do
23
+ context "without the :no_count_if_one option" do
24
+ it "should return \"1 person\"" do
25
+ pluralize(1, "person").should == "1 person"
26
+ end
27
+ end
28
+ context "with the :no_count_if_one option to false" do
29
+ it "should return \"1 person\"" do
30
+ pluralize(1, "person", nil, no_count_if_one: false).should == "1 person"
31
+ end
32
+ end
33
+ context "with the :no_count_if_one option to true" do
34
+ it "should return \"person\"" do
35
+ pluralize(1, "person", nil, no_count_if_one: true).should == "person"
36
+ end
37
+ end
38
+ end
39
+ context "passing a count of 2" do
40
+ context "without the :no_count_if_one option" do
41
+ it "should return \"2 people\"" do
42
+ pluralize(2, "person").should == "2 people"
43
+ end
44
+ end
45
+ context "with the :no_count_if_one option to false" do
46
+ it "should return \"2 people\"" do
47
+ pluralize(2, "person", nil, no_count_if_one: false).should == "2 people"
48
+ end
49
+ end
50
+ context "with the :no_count_if_one option to true" do
51
+ it "should return \"2 people\"" do
52
+ pluralize(2, "person", nil, no_count_if_one: true).should == "2 people"
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pluralize_no_count_if_one
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - zedtux
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Add the missing :no_count_if_one option to the Rails pluralize helper
98
+ email:
99
+ - zedtux@zedroot.org
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .gpairrc
106
+ - .rspec
107
+ - .ruby-gemset
108
+ - .ruby-version
109
+ - .travis.yml
110
+ - Gemfile
111
+ - LICENSE
112
+ - LICENSE.txt
113
+ - README.md
114
+ - Rakefile
115
+ - lib/pluralize_no_count_if_one.rb
116
+ - lib/pluralize_no_count_if_one/action_view/helpers.rb
117
+ - lib/pluralize_no_count_if_one/railtie.rb
118
+ - lib/pluralize_no_count_if_one/version.rb
119
+ - pluralize_no_count_if_one.gemspec
120
+ - spec/spec_helper.rb
121
+ - spec/views/action_view/helpers_spec.rb
122
+ homepage: https://github.com/zedtux/pluralize_no_count_if_one
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.1.11
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: In the case you set the new option :no_count_if_one to true and the collection
146
+ has only one value it will not show the count.
147
+ test_files:
148
+ - spec/spec_helper.rb
149
+ - spec/views/action_view/helpers_spec.rb