cocos 0.2.0 → 0.2.1
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/cocos/version.rb +1 -1
- data/lib/cocos.rb +69 -17
- 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: 40d870d3371a969672ba3e6b61dfb5cfbfae18809fa2edb96c8a3dbdfa44f1e8
|
4
|
+
data.tar.gz: f811adb7be939ff1dd90108fe16bf036f45e40540cbbff81fb7d20d6591c1426
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b504140b89069be5896ab2028263e191475d5d92423fc6df4be069523c2b037b0c28830ec0fa89426e0212007044344ed4c849345e016d12c2c0832575b85920
|
7
|
+
data.tar.gz: 1b5a4741a03b48740fb4868bf54c054382dbee3a3f7b7cca243d2393c88cc0c6cb5b5d75e593d5c3bdec075d3df32a714eb4f7ec861572dfd9c3e4a2278f9548
|
data/lib/cocos/version.rb
CHANGED
data/lib/cocos.rb
CHANGED
@@ -40,14 +40,35 @@ module Kernel
|
|
40
40
|
|
41
41
|
|
42
42
|
|
43
|
+
################
|
44
|
+
# private helpers - keep along here - why? why not?
|
45
|
+
|
46
|
+
##### check if path starts with http:// or https://
|
47
|
+
## if yes, assume it's a download
|
48
|
+
DOWNLOAD_RX = %r{^https?://}i
|
49
|
+
|
50
|
+
## note: hack - use !! to force nil (no match) to false
|
51
|
+
## and matchdata to true
|
52
|
+
def _download?( path )
|
53
|
+
!! DOWNLOAD_RX.match( path )
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
|
43
58
|
## todo: add symbolize options a la read_json
|
44
59
|
## add sep options
|
45
60
|
def read_csv( path, headers: true )
|
46
|
-
|
47
|
-
|
61
|
+
|
62
|
+
if _download?( path )
|
63
|
+
parse_csv( _wget!( path ).text,
|
64
|
+
headers: headers )
|
48
65
|
else
|
49
|
-
|
50
|
-
|
66
|
+
if headers
|
67
|
+
CsvHash.read( path )
|
68
|
+
else
|
69
|
+
Csv.read( path )
|
70
|
+
end
|
71
|
+
end
|
51
72
|
end
|
52
73
|
|
53
74
|
def parse_csv( str, headers: true )
|
@@ -63,7 +84,11 @@ end
|
|
63
84
|
## for alternate shortcut for read_csv / parse_csv w/ headers: false
|
64
85
|
## returning arrays of strings
|
65
86
|
def read_data( path )
|
66
|
-
|
87
|
+
if _download?( path )
|
88
|
+
read_data( _wget!( path ).text )
|
89
|
+
else
|
90
|
+
Csv.read( path )
|
91
|
+
end
|
67
92
|
end
|
68
93
|
|
69
94
|
def parse_data( str )
|
@@ -73,7 +98,11 @@ end
|
|
73
98
|
|
74
99
|
|
75
100
|
def read_tab( path )
|
76
|
-
|
101
|
+
if _download?( path )
|
102
|
+
parse_tab( _wget!( path ).text )
|
103
|
+
else
|
104
|
+
Tab.read( path )
|
105
|
+
end
|
77
106
|
end
|
78
107
|
|
79
108
|
def parse_tab( str )
|
@@ -83,16 +112,17 @@ end
|
|
83
112
|
|
84
113
|
## todo: add symbolize options ???
|
85
114
|
def read_json( path )
|
86
|
-
|
115
|
+
JSON.parse( read_text( path ))
|
87
116
|
end
|
88
117
|
|
89
118
|
def parse_json( str )
|
90
119
|
JSON.parse( str )
|
91
120
|
end
|
92
121
|
|
122
|
+
|
93
123
|
### todo/check: use parse_safeyaml or such? (is default anyway?) - why? why not?
|
94
124
|
def read_yaml( path )
|
95
|
-
|
125
|
+
YAML.load( read_text( path ))
|
96
126
|
end
|
97
127
|
|
98
128
|
def parse_yaml( str )
|
@@ -101,7 +131,7 @@ end
|
|
101
131
|
|
102
132
|
|
103
133
|
def read_ini( path )
|
104
|
-
|
134
|
+
INI.load( read_text( path ))
|
105
135
|
end
|
106
136
|
|
107
137
|
def parse_ini( str )
|
@@ -115,6 +145,9 @@ alias_method :parse_conf, :parse_ini
|
|
115
145
|
|
116
146
|
|
117
147
|
def read_text( path )
|
148
|
+
if _download?( path )
|
149
|
+
_wget!( path ).text
|
150
|
+
else
|
118
151
|
## todo/check: add universal newline mode or such?
|
119
152
|
## e.g. will always convert all
|
120
153
|
## newline variants (\n|\r|\n\r) to "universal" \n only
|
@@ -122,15 +155,20 @@ def read_text( path )
|
|
122
155
|
f.read
|
123
156
|
end
|
124
157
|
txt
|
158
|
+
end
|
125
159
|
end
|
126
160
|
alias_method :read_txt, :read_text
|
127
161
|
|
128
162
|
|
129
163
|
def read_blob( path )
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
164
|
+
if _download?( path )
|
165
|
+
_wget!( path ).blob
|
166
|
+
else
|
167
|
+
blob = File.open( path, 'rb' ) do |f|
|
168
|
+
f.read
|
169
|
+
end
|
170
|
+
blob
|
171
|
+
end
|
134
172
|
end
|
135
173
|
alias_method :read_binary, :read_blob
|
136
174
|
alias_method :read_bin, :read_blob
|
@@ -140,12 +178,15 @@ alias_method :read_bin, :read_blob
|
|
140
178
|
|
141
179
|
## todo/check: remove \n (or\r or \r\n) from line
|
142
180
|
## ruby (by default) keeps the newline - follow tradition? why? why not?
|
181
|
+
## add/offer chomp: true/false option or such - why? why not?
|
182
|
+
## see String.lines in rdoc
|
143
183
|
##
|
144
184
|
def read_lines( path )
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
185
|
+
read_text( path ).lines
|
186
|
+
end
|
187
|
+
|
188
|
+
def parse_lines( str )
|
189
|
+
str.lines
|
149
190
|
end
|
150
191
|
|
151
192
|
|
@@ -211,6 +252,17 @@ end
|
|
211
252
|
|
212
253
|
|
213
254
|
|
255
|
+
## private helper - make public -why? why not?
|
256
|
+
def _wget!( url, **kwargs )
|
257
|
+
res = Webclient.get( url, **kwargs )
|
258
|
+
|
259
|
+
## check/todo - use a different exception/error - keep RuntimeError - why? why not?
|
260
|
+
raise RuntimeError, "HTTP #{res.status.code} - #{res.status.message}" if res.status.nok?
|
261
|
+
|
262
|
+
res
|
263
|
+
end
|
264
|
+
|
265
|
+
|
214
266
|
end # module Kernel
|
215
267
|
|
216
268
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cocos
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: csvreader
|