k_util 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/k_util.rb +10 -0
- data/lib/k_util/console_helper.rb +2 -4
- data/lib/k_util/data_helper.rb +3 -9
- data/lib/k_util/file_helper.rb +2 -8
- data/lib/k_util/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8615e74388467bff65c418f4367b9a6946ad9f1ed9dc7aaee45ccd81774a437
|
4
|
+
data.tar.gz: 8c752c2c0210b4aea25afeb5a6d41847a138d11a2af5e16bcad0d8ea35499b5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac0a9551cc6a4c8c463e0bdc8b4b209695d5d8a1fcfd7c633cdc33488725d81f9479f91e54ea3393d66312543135149a9838dce70eeb46943e1b868be564aa31
|
7
|
+
data.tar.gz: 6512cfa298e0bf08f3b29776326dd8e8be3ebe8a0c3162c2be8764cf791748d5421ee4efd14606c65b8192351e3163a8249a610abd9481258744dae95e045d33
|
data/lib/k_util.rb
CHANGED
@@ -9,4 +9,14 @@ require 'k_util/file_helper'
|
|
9
9
|
module KUtil
|
10
10
|
# raise KUtil::Error, 'Sample message'
|
11
11
|
# class Error < StandardError; end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
attr_accessor :console
|
15
|
+
attr_accessor :data
|
16
|
+
attr_accessor :file
|
17
|
+
end
|
18
|
+
|
19
|
+
KUtil.console = KUtil::ConsoleHelper.new
|
20
|
+
KUtil.data = KUtil::DataHelper.new
|
21
|
+
KUtil.file = KUtil::FileHelper.new
|
12
22
|
end
|
@@ -11,14 +11,12 @@ module KUtil
|
|
11
11
|
# Convert a hash into a deep OpenStruct or array an array
|
12
12
|
# of objects into an array of OpenStruct
|
13
13
|
# Generate hyper link encoded string for the console
|
14
|
-
def
|
14
|
+
def file_hyperlink(text, file)
|
15
15
|
"\u001b]8;;file://#{file}\u0007#{text}\u001b]8;;\u0007"
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
18
|
+
def hyperlink(text, link)
|
19
19
|
"\u001b]8;;#{link}\u0007#{text}\u001b]8;;\u0007"
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
24
|
-
KUtil.console = KUtil::ConsoleHelper
|
data/lib/k_util/data_helper.rb
CHANGED
@@ -2,15 +2,11 @@
|
|
2
2
|
|
3
3
|
# Provide data object helper functions
|
4
4
|
module KUtil
|
5
|
-
class << self
|
6
|
-
attr_accessor :data
|
7
|
-
end
|
8
|
-
|
9
5
|
# Helper methods attached to the namespace for working with Data
|
10
6
|
class DataHelper
|
11
7
|
# Convert various data types (Hash, Array, Struct) into a deep nested OpenStruct
|
12
8
|
# or an array of deep nested OpenStruct
|
13
|
-
def
|
9
|
+
def to_open_struct(data)
|
14
10
|
case data
|
15
11
|
when Hash
|
16
12
|
OpenStruct.new(data.transform_values { |v| to_open_struct(v) })
|
@@ -28,7 +24,7 @@ module KUtil
|
|
28
24
|
end
|
29
25
|
|
30
26
|
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
31
|
-
def
|
27
|
+
def to_hash(data)
|
32
28
|
# No test yet
|
33
29
|
if data.is_a?(Array)
|
34
30
|
return data.map { |v| v.is_a?(OpenStruct) ? to_hash(v) : v }
|
@@ -49,12 +45,10 @@ module KUtil
|
|
49
45
|
end
|
50
46
|
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
51
47
|
|
52
|
-
def
|
48
|
+
def clean_symbol(value)
|
53
49
|
return value if value.nil?
|
54
50
|
|
55
51
|
value.is_a?(Symbol) ? value.to_s : value
|
56
52
|
end
|
57
53
|
end
|
58
54
|
end
|
59
|
-
|
60
|
-
KUtil.data = KUtil::DataHelper
|
data/lib/k_util/file_helper.rb
CHANGED
@@ -2,13 +2,9 @@
|
|
2
2
|
|
3
3
|
# Provide file helper functions
|
4
4
|
module KUtil
|
5
|
-
class << self
|
6
|
-
attr_accessor :file
|
7
|
-
end
|
8
|
-
|
9
5
|
# Helper methods attached to the namespace for working with Files
|
10
6
|
class FileHelper
|
11
|
-
def
|
7
|
+
def expand_path(filename, base_path = nil)
|
12
8
|
if pathname_absolute?(filename)
|
13
9
|
filename
|
14
10
|
elsif filename.start_with?('~/')
|
@@ -18,10 +14,8 @@ module KUtil
|
|
18
14
|
end
|
19
15
|
end
|
20
16
|
|
21
|
-
def
|
17
|
+
def pathname_absolute?(pathname)
|
22
18
|
Pathname.new(pathname).absolute?
|
23
19
|
end
|
24
20
|
end
|
25
21
|
end
|
26
|
-
|
27
|
-
KUtil.file = KUtil::FileHelper
|
data/lib/k_util/version.rb
CHANGED