w-stdlib 0.0.10 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/w-stdlib/core_ext/string.rb +32 -0
- data/lib/w-stdlib/prelude.rb +35 -0
- data/w-stdlib.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c01012e9f0cd07f8a5e0b1ef8be0bc340a21cb796fb5e2aabffed48a29b108a
|
4
|
+
data.tar.gz: 5d838107d40c9a106f07161ca6ea9f2f115c9f458cb14e7ea5c85c1ebb5bbe06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8f3e5b0f5a4c40b46483ec8393c71b666bdffde94beffac96035b7ed57756f442cb9c4c907dacc67feac2f9be7fe536b37a8c0d55e2c8930fb5315e8f5bb2a5
|
7
|
+
data.tar.gz: 3ad654bef43e5b301ff2777bbe5862c0cd049842eaa3ae16724e61f7ed8470002d7b74adffa9be99794fc21a41118034bfde42dfc25d3b0dad8cf4c8acf6dac7
|
@@ -9,6 +9,14 @@ module StringExt
|
|
9
9
|
YAML.safe_load(self)
|
10
10
|
end
|
11
11
|
|
12
|
+
def yaml_encode
|
13
|
+
to_yaml
|
14
|
+
end
|
15
|
+
|
16
|
+
def yaml_decode
|
17
|
+
from_yaml
|
18
|
+
end
|
19
|
+
|
12
20
|
def from_json
|
13
21
|
JSON.parse self
|
14
22
|
end
|
@@ -25,6 +33,22 @@ module StringExt
|
|
25
33
|
Base64.decode64 self
|
26
34
|
end
|
27
35
|
|
36
|
+
def b64_encode
|
37
|
+
to_b64
|
38
|
+
end
|
39
|
+
|
40
|
+
def b64_decode
|
41
|
+
from_b64
|
42
|
+
end
|
43
|
+
|
44
|
+
def json_encode
|
45
|
+
to_json
|
46
|
+
end
|
47
|
+
|
48
|
+
def json_decode
|
49
|
+
from_json
|
50
|
+
end
|
51
|
+
|
28
52
|
def url_encode
|
29
53
|
CGI.escape self
|
30
54
|
end
|
@@ -105,6 +129,14 @@ module StringExt
|
|
105
129
|
downcase.include? s.downcase
|
106
130
|
end
|
107
131
|
|
132
|
+
def contains?(s)
|
133
|
+
include?(s)
|
134
|
+
end
|
135
|
+
|
136
|
+
def icontains?(s)
|
137
|
+
include_ignore_case?(s)
|
138
|
+
end
|
139
|
+
|
108
140
|
def is_numeric?
|
109
141
|
Float(self)
|
110
142
|
true
|
data/lib/w-stdlib/prelude.rb
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
require 'http'
|
2
|
+
require 'json'
|
3
|
+
require_relative 'core_ext/string'
|
4
|
+
|
5
|
+
using StringExt
|
6
|
+
|
1
7
|
def fatal(msg, code=1, pref='[!] ')
|
2
8
|
STDERR.puts pref + msg
|
3
9
|
exit code
|
@@ -15,6 +21,35 @@ def json_file(name)
|
|
15
21
|
JSON.parse File.read(name)
|
16
22
|
end
|
17
23
|
|
24
|
+
def read_json(path)
|
25
|
+
json_file(path)
|
26
|
+
end
|
27
|
+
|
28
|
+
def write_json(path, o, pretty=false)
|
29
|
+
json = pretty ? JSON.pretty_generate(o) : o.to_json
|
30
|
+
File.write(path, json)
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_json(url)
|
34
|
+
HTTP.get(url).to_s.from_json
|
35
|
+
end
|
36
|
+
|
37
|
+
def read_lines(path)
|
38
|
+
File.readlines(path).map(&:strip).reject(&:empty?)
|
39
|
+
end
|
40
|
+
|
41
|
+
def stdin_lines
|
42
|
+
$stdin.lines.map(&:strip).reject(&:empty?)
|
43
|
+
end
|
44
|
+
|
45
|
+
def stdin_json
|
46
|
+
$stdin.read.from_json
|
47
|
+
end
|
48
|
+
|
49
|
+
def write_lines(path, lines)
|
50
|
+
File.write(path, lines.join("\n"))
|
51
|
+
end
|
52
|
+
|
18
53
|
def home_join(*paths)
|
19
54
|
home = ENV['HOME']
|
20
55
|
if paths.empty?
|
data/w-stdlib.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |g|
|
2
2
|
g.name = 'w-stdlib'
|
3
|
-
g.version = '0.0.
|
3
|
+
g.version = '0.0.13'
|
4
4
|
g.summary = 'Pre-alpha package that contains abstractions that I find useful when scripting. Not suitable for production use. Breaking changes highly likely even with minor version bumps. Use at your own risk'
|
5
5
|
g.description = g.summary
|
6
6
|
g.authors = ['will@btlr.dev']
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: w-stdlib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- will@btlr.dev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parallel
|