sentencify 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +11 -0
- data/README.md +3 -0
- data/lib/sentencify.rb +10 -8
- data/lib/sentencify/version.rb +1 -1
- data/sentencify.gemspec +1 -1
- metadata +5 -3
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -37,15 +37,18 @@ end
|
|
37
37
|
In your `index.html.erb` view:
|
38
38
|
```rb
|
39
39
|
@users.sentencize(on: :login)
|
40
|
+
@users.sentencize(on: :avatar, image: true)
|
40
41
|
```
|
41
42
|
|
42
43
|
It will display all your users by login with a default limit of 5.
|
43
44
|
You can change this value by passing a limit parameter as following: `limit: 10`
|
45
|
+
** Extra **: You can display images by turning the image option to true.
|
44
46
|
|
45
47
|
### Advanced
|
46
48
|
#### Parameters
|
47
49
|
|
48
50
|
Others parameters:
|
51
|
+
* `image`, default value: false
|
49
52
|
* `empty`, default value: 'No element found'
|
50
53
|
* `words_connector`, default value: ', '
|
51
54
|
* `two_words_connector`, default value: ' and '
|
data/lib/sentencify.rb
CHANGED
@@ -2,10 +2,11 @@ require 'active_support/core_ext/array'
|
|
2
2
|
|
3
3
|
class Array
|
4
4
|
def sentencize(options = {})
|
5
|
-
options.assert_valid_keys(:on, :limit, :empty, :words_connector, :two_words_connector, :last_word_connector, :final_singular_connector, :final_plural_connector)
|
5
|
+
options.assert_valid_keys(:on, :image, :limit, :empty, :words_connector, :two_words_connector, :last_word_connector, :final_singular_connector, :final_plural_connector)
|
6
6
|
|
7
7
|
default_connectors = {
|
8
8
|
on: :title,
|
9
|
+
image: false,
|
9
10
|
limit: 5,
|
10
11
|
empty: 'No element found',
|
11
12
|
words_connector: ', ',
|
@@ -16,28 +17,29 @@ class Array
|
|
16
17
|
}
|
17
18
|
|
18
19
|
if defined?(I18n)
|
19
|
-
i18n_connectors = I18n.translate(:
|
20
|
+
i18n_connectors = I18n.translate(:sentencify, default: {})
|
20
21
|
default_connectors.merge!(i18n_connectors)
|
21
22
|
end
|
22
23
|
|
23
24
|
options = default_connectors.merge!(options)
|
24
25
|
|
26
|
+
will_sentencized = self.map(&options[:on])
|
27
|
+
will_sentencized.map! { |s| "<img src='#{s}' />" } if options[:image]
|
28
|
+
|
25
29
|
case length
|
26
30
|
when 0
|
27
31
|
options[:empty]
|
28
32
|
when 1
|
29
|
-
|
33
|
+
will_sentencized[0]
|
30
34
|
when 2
|
31
|
-
|
32
|
-
"#{elts[0]}#{options[:two_words_connector]}#{elts[1]}"
|
35
|
+
"#{will_sentencized[0]}#{options[:two_words_connector]}#{will_sentencized[1]}"
|
33
36
|
else
|
34
|
-
elts = self.map(&options[:on])
|
35
37
|
if options[:limit] >= length
|
36
|
-
"#{
|
38
|
+
"#{will_sentencized[0...-1].join(options[:words_connector])}#{options[:last_word_connector]}#{will_sentencized[-1]}"
|
37
39
|
else
|
38
40
|
nb_others = length-options[:limit]
|
39
41
|
others = (nb_others != 1) ? options[:final_plural_connector] : options[:final_singular_connector]
|
40
|
-
"#{
|
42
|
+
"#{will_sentencized[0..options[:limit]-1].join(options[:words_connector])}#{options[:last_word_connector]}#{nb_others}#{others}"
|
41
43
|
end
|
42
44
|
end
|
43
45
|
end
|
data/lib/sentencify/version.rb
CHANGED
data/sentencify.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Sentencify::VERSION
|
9
9
|
spec.authors = ['Baptiste Lecocq']
|
10
10
|
spec.email = ['baptiste.lecocq@gmail.com']
|
11
|
-
spec.description = '
|
11
|
+
spec.description = 'With Sentencify, you can create sentences with array of Active Record objects. It supports I18n.'
|
12
12
|
spec.summary = 'Create sentences with array of Active Record objects'
|
13
13
|
spec.homepage = 'https://github.com/baptistelecocq/sentencify'
|
14
14
|
spec.license = 'MIT'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sentencify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-07-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -59,7 +59,8 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
-
description:
|
62
|
+
description: With Sentencify, you can create sentences with array of Active Record
|
63
|
+
objects. It supports I18n.
|
63
64
|
email:
|
64
65
|
- baptiste.lecocq@gmail.com
|
65
66
|
executables: []
|
@@ -69,6 +70,7 @@ files:
|
|
69
70
|
- .gitignore
|
70
71
|
- .ruby-gemset
|
71
72
|
- .ruby-version
|
73
|
+
- CHANGELOG.md
|
72
74
|
- Gemfile
|
73
75
|
- LICENSE.txt
|
74
76
|
- README.md
|