tzispa_utils 0.2.0 → 0.2.1
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 +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/tzispa/utils/string.rb +39 -8
- data/lib/tzispa/utils/version.rb +1 -1
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c5bb436155051a840c18c851e169692afdec5b6
|
4
|
+
data.tar.gz: d2822691fc761083cfa2db17d34afd3e0f8e4af1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56a2687e8869a0cce036ba60d5770ed6d2509a21994bd7061e4abfd1211a2e10aad7ed2218a1630158c03383557d1b86e2e8cd99b3f6e394ee5ea53301a43f28
|
7
|
+
data.tar.gz: 5324ff5d7a1a09b7017f81f77f6db11c2ce4935da50b993211054cc2a8da576c0c48eeb032dfcf730bf8861755a97b3c55abfeb5107b74fc1b1f028265324156
|
data/CHANGELOG.md
CHANGED
data/lib/tzispa/utils/string.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
require 'i18n'
|
4
2
|
|
5
3
|
module Tzispa
|
@@ -10,9 +8,17 @@ module Tzispa
|
|
10
8
|
NAMESPACE_SEPARATOR = '::'
|
11
9
|
CLASSIFY_SEPARATOR = '_'
|
12
10
|
UNDERSCORE_SEPARATOR = '/'
|
13
|
-
|
11
|
+
DEFAULT_INDENT_CHAR = ' '
|
14
12
|
UNDERSCORE_DIVISION_TARGET = '\1_\2'
|
15
13
|
|
14
|
+
attr_accessor :indent_char
|
15
|
+
|
16
|
+
def initialize(s='')
|
17
|
+
super(s)
|
18
|
+
@indent = 0
|
19
|
+
@indent_char = DEFAULT_INDENT_CHAR
|
20
|
+
end
|
21
|
+
|
16
22
|
def self.constantize(str)
|
17
23
|
self.new(str.to_s).constantize
|
18
24
|
end
|
@@ -32,11 +38,11 @@ module Tzispa
|
|
32
38
|
end
|
33
39
|
|
34
40
|
def camelize
|
35
|
-
|
41
|
+
split(CLASSIFY_SEPARATOR).collect{ |w| w.capitalize }.join
|
36
42
|
end
|
37
43
|
|
38
44
|
def camelize!
|
39
|
-
|
45
|
+
split(CLASSIFY_SEPARATOR).collect!{ |w| w.capitalize }.join
|
40
46
|
end
|
41
47
|
|
42
48
|
def self.underscore(str)
|
@@ -44,7 +50,7 @@ module Tzispa
|
|
44
50
|
end
|
45
51
|
|
46
52
|
def underscore
|
47
|
-
|
53
|
+
dup.tap { |s|
|
48
54
|
s.gsub!(NAMESPACE_SEPARATOR, UNDERSCORE_SEPARATOR)
|
49
55
|
s.gsub!(/([A-Z\d]+)([A-Z][a-z])/, UNDERSCORE_DIVISION_TARGET)
|
50
56
|
s.gsub!(/([a-z\d])([A-Z])/, UNDERSCORE_DIVISION_TARGET)
|
@@ -54,7 +60,7 @@ module Tzispa
|
|
54
60
|
end
|
55
61
|
|
56
62
|
def underscore!
|
57
|
-
|
63
|
+
tap { |s|
|
58
64
|
s.gsub!(NAMESPACE_SEPARATOR, UNDERSCORE_SEPARATOR)
|
59
65
|
s.gsub!(/([A-Z\d]+)([A-Z][a-z])/, UNDERSCORE_DIVISION_TARGET)
|
60
66
|
s.gsub!(/([a-z\d])([A-Z])/, UNDERSCORE_DIVISION_TARGET)
|
@@ -82,14 +88,39 @@ module Tzispa
|
|
82
88
|
options[:convert_spaces] ||= true
|
83
89
|
options[:regexp] ||= /[^-_A-Za-z0-9]/
|
84
90
|
|
85
|
-
|
91
|
+
transliterate(options[:locale]).strip.tap { |str|
|
86
92
|
str.downcase! if options[:downcase]
|
87
93
|
str.gsub!(/\ /,'_') if options[:convert_spaces]
|
88
94
|
str.gsub!(options[:regexp], '')
|
89
95
|
}
|
90
96
|
end
|
91
97
|
|
98
|
+
def indenter(str=nil, count=0)
|
99
|
+
@indent += count if count > 0
|
100
|
+
self.class.indentize(str&.to_s || self, @indent, @indent_char)
|
101
|
+
end
|
102
|
+
|
103
|
+
def unindenter(str=nil, count=0)
|
104
|
+
@indent -= count if count > 0 && @indent-count >= 0
|
105
|
+
@indent = 0 if count > 0 && @indent-count < 0
|
106
|
+
self.class.indentize(str&.to_s || self, @indent, @indent_char)
|
107
|
+
end
|
108
|
+
|
109
|
+
# Indent a string by count chars
|
110
|
+
def indentize(count, char = ' ')
|
111
|
+
gsub(/([^\n]*)(\n|$)/) do |match|
|
112
|
+
last_iteration = ($1 == "" && $2 == "")
|
113
|
+
line = ""
|
114
|
+
line << (char * count) unless last_iteration
|
115
|
+
line << $1
|
116
|
+
line << $2
|
117
|
+
line
|
118
|
+
end
|
119
|
+
end
|
92
120
|
|
121
|
+
def self.indentize(str, count, char = ' ')
|
122
|
+
self.new(str).indentize(count, char)
|
123
|
+
end
|
93
124
|
|
94
125
|
end
|
95
126
|
end
|
data/lib/tzispa/utils/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tzispa_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
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-03-
|
12
|
-
dependencies:
|
11
|
+
date: 2016-03-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: i18n
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.7'
|
13
27
|
description: Utilities for Tzispa
|
14
28
|
email:
|
15
29
|
- japinero@area-integral.com
|
@@ -46,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
60
|
version: '0'
|
47
61
|
requirements: []
|
48
62
|
rubyforge_project:
|
49
|
-
rubygems_version: 2.
|
63
|
+
rubygems_version: 2.4.8
|
50
64
|
signing_key:
|
51
65
|
specification_version: 4
|
52
66
|
summary: Utilities for Tzispa
|