string_awesome 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f78f62624cff19d1223034e0de8c83df051ba22e
4
- data.tar.gz: 6b0f254d8cd5c41a76bda6db88d2c0a0e649c052
3
+ metadata.gz: 2cd58efc570f7ce893ccca18c174c728c4ab1680
4
+ data.tar.gz: 0fae2cf2ffecce0691336304b302993e0d813643
5
5
  SHA512:
6
- metadata.gz: 772e18e331e7e45e6b8e394d6ad9263d1316239a58ce7dcbbfc852254260ce1c0b12f64d5e9f95be73221165437457b873dc936905ff222a10283945673e90c8
7
- data.tar.gz: b4fb338d8557c6ae399b5e2e49cf7b22d350bb31415a841cc4f482b9ca02b184037cde817a26b3d828847ad6c3c1fa868dd171b7998b4ffd6b9558d03d9ffce6
6
+ metadata.gz: 4392918a8bc45ecc107c47bd94f69a233e32f36c1faf22c9f28aa8d387225f224f51c02ee1751a7f1f54507e3da9de4364394df1c5c0f92ae1a01ddf4b5bb469
7
+ data.tar.gz: 599dad656adfc1cb3fa1e358158ecccaa93a791f3e4607d30326d231979d48acd16c9395091d9d9a41b56b76230667e6a1245d0d113e6e44236b34808f99b93b
@@ -165,7 +165,7 @@ module StringAwesome
165
165
  max_length = (length / 2).round if max_length == 0
166
166
 
167
167
  # Truncates the string
168
- str = self.truncate(max_length, options[:after_a_word]).strip
168
+ str = self.sa_truncate(max_length, options[:after_a_word]).strip
169
169
 
170
170
  # Appends ellipsis
171
171
  str << (options[:html_encoded] == true ? '&hellip;' : '...')
@@ -184,7 +184,7 @@ module StringAwesome
184
184
  # - Indicates the max length expected, before ellipsis, for the result.
185
185
  # after_a_word: (Boolean)
186
186
  # - If true, the ellipsis will be displayed necessarily after a word.
187
- def truncate(length, after_a_word = false)
187
+ def sa_truncate(length, after_a_word = false)
188
188
  str = self[0...length]
189
189
 
190
190
  if after_a_word == true
@@ -216,7 +216,7 @@ module StringAwesome
216
216
  def linkify(options = {})
217
217
  self.gsub!(SA_REGEXES[:url]) do |match|
218
218
  # http://verylongurl...
219
- displayed = _truncate_url match, options[:truncate]
219
+ displayed = truncate_url match, options[:truncate]
220
220
 
221
221
  # Now that we're done with the 'truncate' option, let's remove it...
222
222
  options.delete(:truncate) unless !options
@@ -224,7 +224,7 @@ module StringAwesome
224
224
  # Forces the presence of the 'http://'
225
225
  match = "http://#{match}" unless match =~ SA_REGEXES[:protocol]
226
226
 
227
- "<a href=\"#{match}\"#{_apply_tag_attrs(options)}>#{displayed}</a>"
227
+ "<a href=\"#{match}\"#{apply_tag_attrs(options)}>#{displayed}</a>"
228
228
  end
229
229
  self
230
230
  end
@@ -237,7 +237,7 @@ module StringAwesome
237
237
  # - :class - Value for "class" attribute: <a href="url" class="link">url</a>
238
238
  # - :target - Value for "target" attribute: <a href="url" target="_blank">url</a>
239
239
 
240
- def _apply_tag_attrs(options)
240
+ def apply_tag_attrs(options)
241
241
  options ? options.reduce(' ') { |s, v| s << "#{v[0]}=\"#{v[1]}\" " }.gsub(/\s+$/, '') : ''
242
242
  end
243
243
 
@@ -249,7 +249,7 @@ module StringAwesome
249
249
  # t: (Hash|Integer)
250
250
  # - Where the URL will be truncated.
251
251
 
252
- def _truncate_url(m, t)
252
+ def truncate_url(m, t)
253
253
  t ? (t.instance_of?(Hash) ? m.ellipsis(t[:length], html_encoded: t[:html_encoded]) : m.ellipsis(t)) : m
254
254
  end
255
255
 
@@ -276,10 +276,10 @@ module StringAwesome
276
276
  str.gsub!(SA_REGEXES[:tweet]) do |match|
277
277
  is_hashtag = match =~ /#/
278
278
 
279
- unless _restricted?(is_hashtag, options[:only])
279
+ unless restricted?(is_hashtag, options[:only])
280
280
  match = match.strip
281
281
  attrs = is_hashtag ? ["search?q=%23#{match.gsub(/#/, '')}", :hashtag] : ["#{match.gsub(/@/, '')}", :tt_handle]
282
- match = " <a href=\"https://twitter.com/#{attrs[0]}\"#{_apply_tag_attrs(options[attrs[1]])}>#{match}</a>"
282
+ match = " <a href=\"https://twitter.com/#{attrs[0]}\"#{apply_tag_attrs(options[attrs[1]])}>#{match}</a>"
283
283
  end
284
284
 
285
285
  match
@@ -295,7 +295,7 @@ module StringAwesome
295
295
  # only: (Array)
296
296
  # - Types allowed: :hashtag, :tt_handle.
297
297
 
298
- def _restricted?(is_hashtag, only)
298
+ def restricted?(is_hashtag, only)
299
299
  only and ([:hashtag, :tt_handle] != only.sort) and ((is_hashtag and !only.include?(:hashtag)) or (!is_hashtag and !only.include?(:tt_handle)))
300
300
  end
301
301
  end
@@ -1,3 +1,3 @@
1
1
  module StringAwesome
2
- VERSION = '0.2.4'
2
+ VERSION = '0.2.5'
3
3
  end
@@ -66,16 +66,16 @@ describe String do
66
66
  end
67
67
 
68
68
  #
69
- # String#truncate
69
+ # String#sa_truncate
70
70
  #
71
71
 
72
72
  describe '#truncate' do
73
73
  it 'shoud truncate the text' do
74
- "It's a very loooooong text!".truncate(11).should eq "It's a very"
74
+ "It's a very loooooong text!".sa_truncate(11).should eq "It's a very"
75
75
  end
76
76
 
77
77
  it 'shoud truncate the text after a word' do
78
- "It's a very loooooong text!".truncate(8, true).should eq "It's a"
78
+ "It's a very loooooong text!".sa_truncate(8, true).should eq "It's a"
79
79
  end
80
80
  end
81
81
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: string_awesome
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago Guedes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-07 00:00:00.000000000 Z
11
+ date: 2014-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport