rubyhelper 0.5.1 → 0.6.0
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/lib/rubyhelper/stringhelper.rb +30 -21
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c50db820531494030fa2a98274eb72f7f57fe28f
|
|
4
|
+
data.tar.gz: 3ce62f101ae31ff6bda9896144bd203b0cface8c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3bb6a8a4a8e42680cac5e1f0673763a68cf69b709b0f6ee8d73f6154064acb8baa86ac74f7910a3e27f569dacad77378298f3f663e016301d002a2e05d1e7652
|
|
7
|
+
data.tar.gz: 50e93914f99ebaf246e78e245130547436d959d392e3f1aa3fe437c14d8b57bd101506af5cefc7f10f4dbb739ab223027751b0b5030d4182398ff85edf602c6c
|
|
@@ -5,21 +5,21 @@ require 'digest'
|
|
|
5
5
|
|
|
6
6
|
module StringHelper
|
|
7
7
|
|
|
8
|
+
# UTF-8 encoding and replace invalid chars, Remove accents from the string. Change the case as first argument if not nil
|
|
8
9
|
# == Params
|
|
9
10
|
# case_mod: nil (not changement), :upcase, :capitalize or :downcase
|
|
10
11
|
# replace: if a char is not utf8 valid, character will replace it
|
|
11
|
-
# UTF-8 encoding and replace invalid chars, Remove accents from the string. Change the case as first argument
|
|
12
12
|
def to_plain(case_mod = nil, replace= " ")
|
|
13
13
|
return self.p.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '').to_case(case_mod)
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
# Remove accents
|
|
17
|
-
def p
|
|
16
|
+
# Remove accents from the string, and replace it by the same letter in ASCII
|
|
17
|
+
def p
|
|
18
18
|
return self.tr("ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝýÿŶŷŸŹźŻżŽž",
|
|
19
19
|
"AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDdEEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIIIiiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnNnNnnNnOOOOOOooooooOoOoOoRrRrRrSsSsSsSssTtTtTtUUUUuuuuUuUuUuUuUuUuWwYyyYyYZzZzZz")
|
|
20
20
|
end
|
|
21
|
-
def p!
|
|
22
|
-
return self.replace(self.p
|
|
21
|
+
def p!
|
|
22
|
+
return self.replace(self.p)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
# == Params
|
|
@@ -41,10 +41,11 @@ module StringHelper
|
|
|
41
41
|
return self.replace(self.to_case(case_mod))
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
+
# Return a simple ascii string. Invalid characters will be replaced by "replace" (argument)
|
|
45
|
+
# Accents are removed first and replaced by the equivalent ASCII letter
|
|
44
46
|
# == Params
|
|
45
47
|
# replace: a caracter to replace non-ascii chars
|
|
46
48
|
# case_mod: nil (not changement), :upcase, :capitalize or :downcase
|
|
47
|
-
# return a simple ascii string. Invalid characters will be replaced by "replace" (argument)
|
|
48
49
|
def to_ascii(replace="", case_mod = nil)
|
|
49
50
|
s = String.new
|
|
50
51
|
self.p.each_char do |c|
|
|
@@ -62,12 +63,13 @@ module StringHelper
|
|
|
62
63
|
return f
|
|
63
64
|
end
|
|
64
65
|
|
|
65
|
-
#
|
|
66
|
-
|
|
66
|
+
# to_i with delimiter
|
|
67
|
+
# Example : "12.000.000".to_ii => 12000000
|
|
68
|
+
def to_ii(char=' ')
|
|
67
69
|
self.delete(char.to_s).to_i
|
|
68
70
|
end
|
|
69
71
|
|
|
70
|
-
#CRYXOR
|
|
72
|
+
#CRYXOR (one time pad dirt application)
|
|
71
73
|
def ^(k)
|
|
72
74
|
str = ""
|
|
73
75
|
self.size.times do |i|
|
|
@@ -76,7 +78,7 @@ module StringHelper
|
|
|
76
78
|
return str
|
|
77
79
|
end
|
|
78
80
|
|
|
79
|
-
#SHA2
|
|
81
|
+
#SHA2 shortcuts
|
|
80
82
|
def sha2
|
|
81
83
|
Digest::SHA2.hexdigest(self)
|
|
82
84
|
end
|
|
@@ -84,12 +86,13 @@ module StringHelper
|
|
|
84
86
|
return self.replace(self.sha2)
|
|
85
87
|
end
|
|
86
88
|
|
|
89
|
+
# Get a str with a static length.
|
|
90
|
+
# If the str size > n, reduce the str (keep str from the (param place) )
|
|
91
|
+
# You should check the test files for examples
|
|
87
92
|
# ==Param
|
|
88
93
|
# n: number of char
|
|
89
94
|
# char: char to replace if the initial str is too short
|
|
90
95
|
# place: :begin/:front :end/:back :center/:middle
|
|
91
|
-
# Get a str with a static length.
|
|
92
|
-
# If the str size > n, reduce the str (keep str from the (param place) )
|
|
93
96
|
def static(n, char=' ', place= :back)
|
|
94
97
|
char = char.to_s
|
|
95
98
|
n = n.to_i
|
|
@@ -117,7 +120,7 @@ module StringHelper
|
|
|
117
120
|
return self.replace(self.static(n, char))
|
|
118
121
|
end
|
|
119
122
|
|
|
120
|
-
#Returns true or false if the string if "true" or "false"
|
|
123
|
+
#Returns true or false if the string if "true" or "false". else nil
|
|
121
124
|
def to_t
|
|
122
125
|
case self
|
|
123
126
|
when "true"
|
|
@@ -130,19 +133,25 @@ module StringHelper
|
|
|
130
133
|
end
|
|
131
134
|
|
|
132
135
|
#get only the digits and symbols in the string
|
|
133
|
-
|
|
134
|
-
|
|
136
|
+
# == Params
|
|
137
|
+
# sign: (true/false) if true, keep the - and + signs
|
|
138
|
+
def get_int(sign = true)
|
|
139
|
+
return self.gsub(/[^\-\+\d]/, "") if sign == true
|
|
140
|
+
return self.gsub(/[^\d]/, "")
|
|
135
141
|
end
|
|
136
|
-
def get_int!
|
|
137
|
-
return self.replace(self.get_int)
|
|
142
|
+
def get_int!(sign = true)
|
|
143
|
+
return self.replace(self.get_int(sign))
|
|
138
144
|
end
|
|
139
145
|
|
|
140
146
|
#as get_int but with . and ,
|
|
141
|
-
|
|
142
|
-
|
|
147
|
+
# == Params
|
|
148
|
+
# sign: (true/false) if true, keep the - and + signs
|
|
149
|
+
def get_float(sign = true)
|
|
150
|
+
return self.gsub(/[^\-\+\d\.\,]/, "") if sign == true
|
|
151
|
+
return self.gsub(/[^\d\.\,]/, "") if sign == true
|
|
143
152
|
end
|
|
144
|
-
def get_float!
|
|
145
|
-
return self.replace(self.get_float)
|
|
153
|
+
def get_float!(sign = true)
|
|
154
|
+
return self.replace(self.get_float(sign))
|
|
146
155
|
end
|
|
147
156
|
|
|
148
157
|
# Capitalize a sequence
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubyhelper
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- poulet_a
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-08-
|
|
11
|
+
date: 2014-08-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: A list of utils for the basic Class of ruby.
|
|
14
14
|
email:
|
|
@@ -52,6 +52,6 @@ rubyforge_project:
|
|
|
52
52
|
rubygems_version: 2.4.1
|
|
53
53
|
signing_key:
|
|
54
54
|
specification_version: 4
|
|
55
|
-
summary:
|
|
55
|
+
summary: ''
|
|
56
56
|
test_files: []
|
|
57
57
|
has_rdoc:
|