tzispa_utils 0.2.0 → 0.2.1

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: 89d93a054b3512818bdea0de54bfea3c346a295d
4
- data.tar.gz: 9640dd1294048ade258a8223d87f06924b162da4
3
+ metadata.gz: 1c5bb436155051a840c18c851e169692afdec5b6
4
+ data.tar.gz: d2822691fc761083cfa2db17d34afd3e0f8e4af1
5
5
  SHA512:
6
- metadata.gz: afa3236206dd25f1c799a65d54df1633384667869e376cf4883ecb44970b542871723b0b7f5c3034868221400e330f87caad480e3032a52be9944606702a7339
7
- data.tar.gz: 5d12e36d97c7ac02c3cd11a0a6d3cea591d873b0257540be1127a2c16886e76ee7865ed10bc5be662a891653d774889b62b327293036b04bdaaf4e2ebfdc41c5
6
+ metadata.gz: 56a2687e8869a0cce036ba60d5770ed6d2509a21994bd7061e4abfd1211a2e10aad7ed2218a1630158c03383557d1b86e2e8cd99b3f6e394ee5ea53301a43f28
7
+ data.tar.gz: 5324ff5d7a1a09b7017f81f77f6db11c2ce4935da50b993211054cc2a8da576c0c48eeb032dfcf730bf8861755a97b3c55abfeb5107b74fc1b1f028265324156
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  Tzispa Utils
2
2
 
3
+ ## v0.2.1
4
+ - Add string indentation utility
5
+
3
6
  ## v0.2.0
4
7
  - Added urlize and transliterate to Tzispa::Utils::String
5
8
  - Make Tzispa::Utils::String a subclass of ::String for better usability
@@ -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
- self.split(CLASSIFY_SEPARATOR).collect{ |w| w.capitalize }.join
41
+ split(CLASSIFY_SEPARATOR).collect{ |w| w.capitalize }.join
36
42
  end
37
43
 
38
44
  def camelize!
39
- self.split(CLASSIFY_SEPARATOR).collect!{ |w| w.capitalize }.join
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
- self.dup.tap { |s|
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
- self.tap { |s|
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
- self.transliterate(options[:locale]).strip.tap { |str|
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
@@ -3,7 +3,7 @@
3
3
  module Tzispa
4
4
  module Utils
5
5
 
6
- VERSION = '0.2.0'
6
+ VERSION = '0.2.1'
7
7
  NAME = 'Tzispa Utils'
8
8
  GEM_NAME = 'tzispa_utils'
9
9
 
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.0
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-09 00:00:00.000000000 Z
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.5.1
63
+ rubygems_version: 2.4.8
50
64
  signing_key:
51
65
  specification_version: 4
52
66
  summary: Utilities for Tzispa