friendly_extensions 0.0.66 → 0.0.69
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/string_and_more.rb +107 -91
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c725237024baa680e26dfdb5d18efdc1a4a68fd3
|
4
|
+
data.tar.gz: 913e3aeeca23e2695134b9714b440a80da38306b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e35b6b2cc1dacc8ff9c7f509dceadfed154392d48c14568201a3387bc83dce55721d529accbd0de48fc19d52d4d0732109e7cd9aceba11b3316be00af8974f18
|
7
|
+
data.tar.gz: 3124a5eb010a03f4ed34984aa2336823c6c8435fd27de812cf33e8a74692618ab64ffc576ac017a782c0a87bde8b70ea22337679b1a272760cc26895fa95f858
|
data/lib/string_and_more.rb
CHANGED
@@ -22,6 +22,10 @@ module StringAndMore
|
|
22
22
|
|
23
23
|
# Array with all strings which can be encrypted
|
24
24
|
STRING_BASE = STRING_CHARSETS.values.join("")
|
25
|
+
|
26
|
+
# Encode String Base with custom secrect key
|
27
|
+
#SHUFFLED_STRING_BASE = STRING_CHARSETS.values.sort_by {|y| STRING_CHARSETS.values.map.with_index {|x,i| STRING_BASE.split("").reverse[i].hex * x.hex }[STRING_CHARSETS.values.index(y)] }
|
28
|
+
|
25
29
|
|
26
30
|
# Returns random String, for Passwords, Captachs etc..
|
27
31
|
# could create :upcase, :downcase, :numbers or :all
|
@@ -56,7 +60,7 @@ module StringAndMore
|
|
56
60
|
end
|
57
61
|
|
58
62
|
# Create string with german date format to Date
|
59
|
-
|
63
|
+
def to_date
|
60
64
|
# Try German
|
61
65
|
matched_date = self.match(/((0|1|2|3)[0-9]{1})\.(0[0-9]{1}|10|11|12)\.[0-9]{4}/)
|
62
66
|
|
@@ -70,7 +74,7 @@ module StringAndMore
|
|
70
74
|
end
|
71
75
|
|
72
76
|
raise ArgumentError, "String has no date like DD.MM.YYYY or YYYY-DD-MM" if matched_date.nil?
|
73
|
-
|
77
|
+
end
|
74
78
|
|
75
79
|
|
76
80
|
def to_number(type = :float)
|
@@ -134,143 +138,155 @@ module StringAndMore
|
|
134
138
|
return str
|
135
139
|
end
|
136
140
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
141
|
+
def limit(l=20)
|
142
|
+
if self.size > l
|
143
|
+
s = self.size
|
144
|
+
s2 = (((self.size-1)/2).round)
|
145
|
+
first = self.slice(0..s2)
|
142
146
|
last = self.slice(s2+1..-1)
|
143
147
|
|
144
148
|
l1 = (l/2).round
|
145
149
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
150
|
+
"#{first.first(l1)}...#{last.last(l1)}"
|
151
|
+
else
|
152
|
+
return self
|
153
|
+
end
|
154
|
+
end
|
151
155
|
|
152
156
|
|
153
157
|
|
154
158
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
159
|
+
def to_datetime
|
160
|
+
date = self.split(" ").first
|
161
|
+
time = self.split(" ").last.split(":")
|
162
|
+
DateTime.new(date.split(".")[2].to_i, date.split(".")[1].to_i, date.split(".")[0].to_i, time.first.to_i, time.last.to_i)
|
163
|
+
end
|
160
164
|
|
161
165
|
|
162
|
-
|
163
|
-
|
164
|
-
|
166
|
+
def clear_html(options = {})
|
167
|
+
ActionView::Base.full_sanitizer.sanitize(self, :tags => options[:tags] )
|
168
|
+
end
|
165
169
|
|
166
|
-
|
167
|
-
|
168
|
-
|
170
|
+
def replace_html(from, to)
|
171
|
+
new_text = self
|
172
|
+
new_text = new_text.gsub("<#{from}>", "<#{to}>")
|
169
173
|
new_text = new_text.gsub("</#{from}>", "</#{to}>")
|
170
174
|
return new_text
|
171
|
-
|
175
|
+
end
|
172
176
|
|
173
|
-
|
177
|
+
def to_model
|
174
178
|
self.singularize.camelize.constantize
|
175
|
-
|
179
|
+
end
|
176
180
|
|
177
|
-
|
178
|
-
|
179
|
-
|
181
|
+
def to_a
|
182
|
+
return [self]
|
183
|
+
end
|
180
184
|
|
181
|
-
|
185
|
+
#== HTML Styling
|
182
186
|
# as the function names say
|
183
187
|
|
184
|
-
|
188
|
+
def bold
|
185
189
|
"<b>#{self}</b>".html_safe
|
186
|
-
|
190
|
+
end
|
187
191
|
|
188
|
-
|
192
|
+
def ital
|
189
193
|
"<i>#{self}</i>".html_safe
|
190
|
-
|
194
|
+
end
|
191
195
|
|
192
|
-
|
196
|
+
def span
|
193
197
|
"<span>#{self}</span>".html_safe
|
194
|
-
|
198
|
+
end
|
195
199
|
|
196
|
-
|
200
|
+
def uline
|
197
201
|
"<u>#{self}</u>".html_safe
|
198
|
-
|
202
|
+
end
|
199
203
|
|
200
204
|
def nbsp
|
201
205
|
self.gsub(" ", " ").html_safe
|
202
206
|
end
|
203
207
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
208
|
+
def replace_entities(mode = :html, options = {})
|
209
|
+
str = self
|
210
|
+
Chars2Remove::ENTITIES.each do |orig, rep|
|
211
|
+
str = str.gsub(orig, rep[mode])
|
212
|
+
end
|
213
|
+
return str.html_safe
|
214
|
+
end
|
211
215
|
|
212
|
-
|
213
|
-
|
214
|
-
|
216
|
+
def add_brs
|
217
|
+
return self.gsub("\n", "<br />")
|
218
|
+
end
|
215
219
|
|
216
|
-
|
220
|
+
#== colorization in console
|
217
221
|
|
218
|
-
|
219
|
-
|
220
|
-
|
222
|
+
def colorize(color_code)
|
223
|
+
"\e[#{color_code};40m#{self}\e[0m"
|
224
|
+
end
|
221
225
|
|
222
|
-
|
223
|
-
|
224
|
-
|
226
|
+
def red
|
227
|
+
colorize(31)
|
228
|
+
end
|
225
229
|
|
226
|
-
|
227
|
-
|
228
|
-
|
230
|
+
def green
|
231
|
+
colorize(32)
|
232
|
+
end
|
229
233
|
|
230
|
-
|
231
|
-
|
232
|
-
|
234
|
+
def yellow
|
235
|
+
colorize(33)
|
236
|
+
end
|
233
237
|
|
234
|
-
|
235
|
-
|
236
|
-
|
238
|
+
def pink
|
239
|
+
colorize(35)
|
240
|
+
end
|
237
241
|
|
238
242
|
|
239
|
-
|
240
|
-
|
243
|
+
#== Numerische encription
|
244
|
+
# cool thing for simple encrypt and decrypt strings
|
241
245
|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
246
|
+
def numberize(options = {})
|
247
|
+
# Basisarray das alle zeichen enthält die verschlüsselt werden können
|
248
|
+
string_array = STRING_BASE.split("")
|
249
|
+
|
250
|
+
if options[:token]
|
251
|
+
string_array = string_array.sort_by {|x| x.hash*options[:token].inspect.bytes.join("").to_i}
|
252
|
+
end
|
253
|
+
|
254
|
+
# Nur Zahlen und buchstaben für die verschlüsselung/mix nehmen wg. URLs
|
255
|
+
string_array_filtered = string_array.select {|s| !s.match(/[a-zA-Z0-9\-_]/).nil? }
|
256
|
+
splitted = self.split("")
|
249
257
|
|
250
|
-
|
258
|
+
numbered_string = ""
|
251
259
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
260
|
+
splitted.each do |s|
|
261
|
+
position = string_array.index(s)
|
262
|
+
if !position.nil?
|
263
|
+
numbered_string << (position.to_s.rjust(2, "0")+string_array_filtered[rand(string_array_filtered.size-1)])
|
264
|
+
end
|
265
|
+
end
|
258
266
|
|
259
|
-
|
260
|
-
|
267
|
+
return options[:base_64] == true ? Base64.encode64(numbered_string) : numbered_string
|
268
|
+
end
|
261
269
|
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
+
def denumberize(options = {})
|
271
|
+
string_array = STRING_BASE.split("")
|
272
|
+
|
273
|
+
if options[:token]
|
274
|
+
string_array = string_array.sort_by {|x| x.hash*options[:token].inspect.bytes.join("").to_i}
|
275
|
+
end
|
276
|
+
|
277
|
+
real_string = ""
|
278
|
+
(options[:base_64] == true ? Base64.decode64(self) : self ).scan(/[0-9]{2}.{1}/).each do |s|
|
279
|
+
real_string << string_array[s.first(2).to_i]
|
280
|
+
end
|
281
|
+
return real_string
|
282
|
+
end
|
283
|
+
|
284
|
+
|
285
|
+
|
270
286
|
|
271
287
|
|
272
|
-
|
273
288
|
end
|
289
|
+
|
274
290
|
|
275
291
|
Symbol.class_eval do
|
276
292
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: friendly_extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.69
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Eck
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|