tzispa_utils 0.3.5 → 0.3.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 31d614392f03ecdc4ee5a1f0e0935264aa7cc287
4
- data.tar.gz: 1e1d19d242249a5ac60f4b35ba33d1fea7502215
2
+ SHA256:
3
+ metadata.gz: 3956cbb97d86021e1c2392fe4e4931c043723518a285e3d03b6ab0572f1e6540
4
+ data.tar.gz: b00ccbe0e15adc4a3a24e569e5b8b864a7535e46609095c52ceb643979c7724c
5
5
  SHA512:
6
- metadata.gz: a044bae8aebb8fc7bf1b704a173af64d905c49456298350e94cb1cc6a917c11fb1069818fb367de56e9ea120bc4866549ef7db18b77ac71a11af639fe94a2420
7
- data.tar.gz: '01075790cc0e996f8e0e922d0b912282bcdfd51b22c1618b982f901514e0224111be826aef10c321b68633664215e04912e629393af794fbde047cc10cab33e3'
6
+ metadata.gz: 5bb6e9aa8ce1a70161b653968668356f3735f9d3d175a34a669943a46c01b1480dd3d4d666fda1c4c41d67a86b390e9d180be67dd8d2c6c013922da982db111a
7
+ data.tar.gz: 3fcba6d1fe5dd3535be90e5f0b8009a2793f5cc5aaf2ce30006581b09eb1b5f3dde7853c96e9ca3d5de87d627c88a45e18c00e75f36b9bd4af6e7c1b85fd47b7
@@ -1,5 +1,8 @@
1
1
  Tzispa Utils
2
2
 
3
+ ## v0.3.6
4
+ - added fix_encoding in string refine
5
+
3
6
  ## v0.3.5
4
7
  - constants autoloading
5
8
  - tests fixes
@@ -13,6 +13,7 @@ module Tzispa
13
13
  UNDERSCORE_SEPARATOR = '/'
14
14
  DOT_SEPARATOR = '.'
15
15
  UNDERSCORE_DIVISION_TARGET = '\1_\2'
16
+ DEFAULT_ENCODING = 'UTF-8'
16
17
 
17
18
  refine String do
18
19
  def constantize
@@ -30,7 +31,7 @@ module Tzispa
30
31
  end
31
32
 
32
33
  def camelize
33
- split(CLASSIFY_SEPARATOR).collect(&:capitalize).join
34
+ dup.camelize!
34
35
  end
35
36
 
36
37
  def camelize!
@@ -38,13 +39,7 @@ module Tzispa
38
39
  end
39
40
 
40
41
  def dottize
41
- dup.tap do |s|
42
- s.gsub!(NAMESPACE_SEPARATOR, DOT_SEPARATOR)
43
- s.gsub!(/([A-Z\d]+)([A-Z][a-z])/, UNDERSCORE_DIVISION_TARGET)
44
- s.gsub!(/([a-z\d])([A-Z])/, UNDERSCORE_DIVISION_TARGET)
45
- s.gsub!(/[[:space:]]|\-/, UNDERSCORE_DIVISION_TARGET)
46
- s.downcase!
47
- end
42
+ dup.dottize!
48
43
  end
49
44
 
50
45
  def dottize!
@@ -58,7 +53,7 @@ module Tzispa
58
53
  end
59
54
 
60
55
  def underscore
61
- dup.tap(&:underscore!)
56
+ dup.underscore!
62
57
  end
63
58
 
64
59
  def underscore!
@@ -71,20 +66,29 @@ module Tzispa
71
66
  end
72
67
  end
73
68
 
69
+ def fix_encoding(src_enc, dest_enc = DEFAULT_ENCODING)
70
+ dup.fix_encoding src_enc, dest_enc
71
+ end
72
+
73
+ def fix_encoding!(src_enc, dest_enc = DEFAULT_ENCODING)
74
+ tap do |s|
75
+ s.force_encoding(src_enc).encode(dest_enc)
76
+ end
77
+ end
78
+
74
79
  def indentize(count, char = ' ')
75
- dup.tap { |str| str.indentize! count, char }
80
+ dup.indentize!(count, char)
76
81
  end
77
82
 
78
83
  # Indent a string by count chars
79
84
  def indentize!(count, char = ' ')
80
- gsub!(/([^\n]*)(\n|$)/) do
81
- s1 = Regexp.last_match(1)
82
- s2 = Regexp.last_match(2)
83
- last_iteration = (s1 == '' && s2 == '')
84
- line = String.new
85
- line << (char * count) unless last_iteration
86
- line << s1 << s2
87
- line
85
+ tap do |s|
86
+ s.gsub!(/([^\n]*)(\n|$)/) do
87
+ s1 = Regexp.last_match(1)
88
+ s2 = Regexp.last_match(2)
89
+ not_empty = s1 != '' || s2 != ''
90
+ "#{char * count}#{s1}#{s2}" if not_empty
91
+ end
88
92
  end
89
93
  end
90
94
 
@@ -103,14 +107,14 @@ module Tzispa
103
107
  # * :convert_spaces => Convert space to underscore (defaults to true)
104
108
  # * :regexp => matching characters that will be removed (defaults to /[^-_A-Za-z0-9]/)
105
109
  def urlize(options = {})
106
- options[:downcase] ||= true
107
- options[:convert_spaces] ||= true
108
- options[:regexp] ||= /[^-_A-Za-z0-9]/
109
-
110
- transliterate(options[:locale]).strip.tap do |str|
111
- str.downcase! if options[:downcase]
112
- str.tr!(' ', '_') if options[:convert_spaces]
113
- str.gsub!(options[:regexp], '')
110
+ downcase = options[:downcase] ||= true
111
+ convert_spaces = options[:convert_spaces] ||= true
112
+ regexp = options[:regexp] ||= /[^-_A-Za-z0-9]/
113
+ locale = options[:locale]
114
+ transliterate(locale).strip.tap do |str|
115
+ str.downcase! if downcase
116
+ str.tr!(' ', '_') if convert_spaces
117
+ str.gsub!(regexp, '')
114
118
  end
115
119
  end
116
120
 
@@ -147,7 +151,7 @@ module Tzispa
147
151
 
148
152
  def integer?(base = 10)
149
153
  Integer(self, base)
150
- rescue
154
+ rescue StandardError
151
155
  false
152
156
  end
153
157
 
@@ -173,6 +177,10 @@ module Tzispa
173
177
  String.new(str).constantize
174
178
  end
175
179
 
180
+ def fix_encoding(str, src_enc, dest_enc = DEFAULT_ENCODING)
181
+ String.new(str).fix_encoding(src_enc, dest_enc)
182
+ end
183
+
176
184
  def urlize(str)
177
185
  String.new(str).urlize
178
186
  end
@@ -3,7 +3,7 @@
3
3
  module Tzispa
4
4
  module Utils
5
5
 
6
- VERSION = '0.3.5'
6
+ VERSION = '0.3.6'
7
7
  NAME = 'Tzispa Utils'
8
8
  GEM_NAME = 'tzispa_utils'
9
9
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tzispa_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Antonio Piñero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-12 00:00:00.000000000 Z
11
+ date: 2017-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  version: '0'
130
130
  requirements: []
131
131
  rubyforge_project:
132
- rubygems_version: 2.6.13
132
+ rubygems_version: 2.7.3
133
133
  signing_key:
134
134
  specification_version: 4
135
135
  summary: Utilities for Tzispa