tzispa_utils 0.2.2 → 0.2.3

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: 77125d8627c9bdb1de850ec93e48233a377558f2
4
- data.tar.gz: ad37d8e675926bbf0015b120f6748fb50a8e34c2
3
+ metadata.gz: 635771a5c6d6022ba305f5df8315e4bf52b0294b
4
+ data.tar.gz: 063e4e4035d8953d3a9d6e9117dc9811626174a6
5
5
  SHA512:
6
- metadata.gz: 00c5eae659271cd1b087548ee5a0083c8ee9949587e8cc9e809eeaaa12810d2e3f83809ffb8d30e9ae030f12e774f012cc787337210a2a12653fc1b38196f545
7
- data.tar.gz: b0545451b6a61d4232f13ae6cb1d1891783fb838f6adb6639929e26e3bd725a93fd92f81601ad248efa406e668d7a7c62ab41601072ac852df884e61cde25614
6
+ metadata.gz: cd69e2e1282f476fc70b021b4d66679d8d0d0bfe414a2e434394a72b1c6d0c41481d62c8d13320aa76ca42b898228a86e69dd4bd710c6e0deb7232b2f0a2b37e
7
+ data.tar.gz: 2f5f3b86a9e4e3a3e73b9ea96d201e0cd169348b29ea6ed8b22bc2ad2966935509f7c4ac5c662cdee98e6f8d5e70bc6a70dc2da40065567758c02277e87c6d86
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  Tzispa Utils
2
2
 
3
+ ## v0.2.3
4
+ - add dottize methods in string refinement
5
+ - replace TzString class with String refinement
6
+ - Added length_constraint_wordify method in TzString
7
+
3
8
  ## v0.2.2
4
9
  - Add string indentation utility
5
10
 
@@ -1,20 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'i18n'
2
4
 
3
5
  module Tzispa
4
6
  module Utils
5
7
 
6
- class String < ::String
8
+ refine String do
7
9
 
8
10
  NAMESPACE_SEPARATOR = '::'
9
11
  CLASSIFY_SEPARATOR = '_'
10
12
  UNDERSCORE_SEPARATOR = '/'
13
+ DOT_SEPARATOR = '.'
11
14
  UNDERSCORE_DIVISION_TARGET = '\1_\2'
12
15
 
13
-
14
- def self.constantize(str)
15
- self.new(str.to_s).constantize
16
- end
17
-
18
16
  def constantize
19
17
  names = self.split(NAMESPACE_SEPARATOR)
20
18
  names.shift if names.empty? || names.first.empty?
@@ -25,10 +23,6 @@ module Tzispa
25
23
  constant
26
24
  end
27
25
 
28
- def self.camelize(str)
29
- self.new(str.to_s).camelize
30
- end
31
-
32
26
  def camelize
33
27
  split(CLASSIFY_SEPARATOR).collect{ |w| w.capitalize }.join
34
28
  end
@@ -37,8 +31,24 @@ module Tzispa
37
31
  split(CLASSIFY_SEPARATOR).collect!{ |w| w.capitalize }.join
38
32
  end
39
33
 
40
- def self.underscore(str)
41
- self.new(str.to_s).underscore
34
+ def dottize
35
+ dup.tap { |s|
36
+ s.gsub!(NAMESPACE_SEPARATOR, DOT_SEPARATOR)
37
+ s.gsub!(/([A-Z\d]+)([A-Z][a-z])/, UNDERSCORE_DIVISION_TARGET)
38
+ s.gsub!(/([a-z\d])([A-Z])/, UNDERSCORE_DIVISION_TARGET)
39
+ s.gsub!(/[[:space:]]|\-/, UNDERSCORE_DIVISION_TARGET)
40
+ s.downcase!
41
+ }
42
+ end
43
+
44
+ def dottize!
45
+ tap { |s|
46
+ s.gsub!(NAMESPACE_SEPARATOR, DOT_SEPARATOR)
47
+ s.gsub!(/([A-Z\d]+)([A-Z][a-z])/, UNDERSCORE_DIVISION_TARGET)
48
+ s.gsub!(/([a-z\d])([A-Z])/, UNDERSCORE_DIVISION_TARGET)
49
+ s.gsub!(/[[:space:]]|\-/, UNDERSCORE_DIVISION_TARGET)
50
+ s.downcase!
51
+ }
42
52
  end
43
53
 
44
54
  def underscore
@@ -87,8 +97,34 @@ module Tzispa
87
97
  }
88
98
  end
89
99
 
100
+ def length_constraint_wordify(max, word_splitter=' ')
101
+ ml = 0
102
+ split(word_splitter).take_while { |s| (ml += s.length + 1) <= max }.join(word_splitter)
103
+ end
104
+
105
+ end
106
+
107
+
108
+ refine String.singleton_class do
109
+
110
+ def underscore(str)
111
+ String.new(str&.to_s)&.underscore
112
+ end
113
+
114
+ def camelize(str)
115
+ String.new(str&.to_s)&.camelize
116
+ end
117
+
118
+ def dottize(str)
119
+ String.new(str&.to_s)&.dottize
120
+ end
121
+
122
+ def constantize(str)
123
+ String.new(str&.to_s)&.constantize
124
+ end
125
+
90
126
  end
127
+
128
+
91
129
  end
92
130
  end
93
-
94
- TzString = Tzispa::Utils::String
@@ -3,7 +3,7 @@
3
3
  module Tzispa
4
4
  module Utils
5
5
 
6
- VERSION = '0.2.2'
6
+ VERSION = '0.2.3'
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.2.2
4
+ version: 0.2.3
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: 2016-04-20 00:00:00.000000000 Z
11
+ date: 2016-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -62,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
62
  version: '0'
63
63
  requirements: []
64
64
  rubyforge_project:
65
- rubygems_version: 2.4.8
65
+ rubygems_version: 2.5.2
66
66
  signing_key:
67
67
  specification_version: 4
68
68
  summary: Utilities for Tzispa