cocos 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -1
- data/README.md +5 -8
- data/Rakefile +1 -1
- data/lib/cocos/version.rb +3 -5
- data/lib/cocos.rb +95 -78
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f34f86372be24c8d19abde781cc66b5d9c6b323e09c7620221f30b9e115b786d
|
4
|
+
data.tar.gz: d025bedc0c96372e74339bd4a0ae7fcd56857d23a1678b35c1b2a8aef2b1be12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50b9cc405bb2d5e16900958a55c11fcf02b5854a4410c072cbab51d585c3a656f9a9a8bb4246b51fc7b46d0200d7fefa98ea3bd4d0e95bb455c8e60dc92c6e10
|
7
|
+
data.tar.gz: fc797f93f3f73644b5b6ee6695564ffd4f4f7308aa8412d5d62785baa9301e5cd740ceb017215d7a3417884edcc057044e15c938bea1310c4c217cbb310d188b
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -87,8 +87,7 @@ And so on.
|
|
87
87
|
|
88
88
|
_Read / parse convenience short-cut helpers_
|
89
89
|
|
90
|
-
`read_blob( path )`
|
91
|
-
also known as `read_binary` or `read_bin`
|
90
|
+
`read_blob( path )`
|
92
91
|
|
93
92
|
|
94
93
|
`read_text( path )` <br>
|
@@ -98,14 +97,14 @@ also known as `read_txt`
|
|
98
97
|
`read_lines( path )`
|
99
98
|
|
100
99
|
|
101
|
-
|
102
100
|
`read_json( path )` / `parse_json( str )`
|
103
101
|
|
104
102
|
|
105
|
-
`read_yaml( path )` / `parse_yaml( str )`
|
103
|
+
`read_yaml( path )` / `parse_yaml( str )` <br>
|
104
|
+
also known as `read_yml` / `parse_yml`
|
106
105
|
|
107
106
|
|
108
|
-
`read_csv( path
|
107
|
+
`read_csv( path )` / `parse_csv( str )`
|
109
108
|
|
110
109
|
note: comma-separated values (.csv) reading & parsing service
|
111
110
|
brought to you by the [**csvreader library / gem »**](https://github.com/rubycocos/csvreader/tree/master/csvreader)
|
@@ -113,8 +112,7 @@ brought to you by the [**csvreader library / gem »**](https://github.com/rubyco
|
|
113
112
|
|
114
113
|
`read_data( path )` / `parse_data( str )`
|
115
114
|
|
116
|
-
note: alternate
|
117
|
-
|
115
|
+
note: alternate csv reader / parser; reads data WITHOUT headers, that is, named columns - returns data array not named hash (table)
|
118
116
|
|
119
117
|
|
120
118
|
|
@@ -125,7 +123,6 @@ brought to you by the [**tabreader library / gem »**](https://github.com/rubyco
|
|
125
123
|
|
126
124
|
|
127
125
|
|
128
|
-
|
129
126
|
`read_ini( path )` / `parse_ini( str )` <br>
|
130
127
|
also known as `read_conf / parse_conf`
|
131
128
|
|
data/Rakefile
CHANGED
@@ -12,7 +12,7 @@ Hoe.spec 'cocos' do
|
|
12
12
|
self.urls = { home: 'https://github.com/rubycocos/cocos' }
|
13
13
|
|
14
14
|
self.author = 'Gerald Bauer'
|
15
|
-
self.email = '
|
15
|
+
self.email = 'gerald.bauer@gmail.com'
|
16
16
|
|
17
17
|
# switch extension to .markdown for gihub formatting
|
18
18
|
self.readme_file = 'README.md'
|
data/lib/cocos/version.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
|
2
2
|
module Cocos
|
3
3
|
MAJOR = 0 ## todo: namespace inside version or something - why? why not??
|
4
|
-
MINOR =
|
5
|
-
PATCH =
|
4
|
+
MINOR = 4
|
5
|
+
PATCH = 0
|
6
6
|
VERSION = [MAJOR,MINOR,PATCH].join('.')
|
7
7
|
|
8
8
|
def self.version
|
@@ -14,8 +14,6 @@ module Cocos
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.root
|
17
|
-
File.expand_path( File.dirname(File.dirname(__FILE__) ))
|
17
|
+
File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__) )))
|
18
18
|
end
|
19
|
-
|
20
19
|
end # module Cocos
|
21
|
-
|
data/lib/cocos.rb
CHANGED
@@ -29,8 +29,9 @@ require 'webclient'
|
|
29
29
|
|
30
30
|
#####################
|
31
31
|
# our own code
|
32
|
-
|
33
|
-
|
32
|
+
require_relative 'cocos/version' # note: let version always go first
|
33
|
+
require_relative 'cocos/env' ## e.g. EnvParser
|
34
|
+
|
34
35
|
|
35
36
|
###
|
36
37
|
## read/parse convenience/helper shortcuts
|
@@ -43,138 +44,153 @@ module Kernel
|
|
43
44
|
################
|
44
45
|
# private helpers - keep along here - why? why not?
|
45
46
|
|
46
|
-
##### check if path starts with http:// or https://
|
47
|
-
## if yes, assume it's a download
|
48
|
-
DOWNLOAD_RX = %r{^https?://}i
|
49
47
|
|
50
|
-
##
|
51
|
-
##
|
52
|
-
def _download?( path )
|
53
|
-
!! DOWNLOAD_RX.match( path )
|
54
|
-
end
|
48
|
+
## todo: add symbolize options a la read_json? - why? why not?
|
49
|
+
## add sep options
|
55
50
|
|
51
|
+
def read_csv( path, sep: nil )
|
52
|
+
opts = {}
|
53
|
+
opts[:sep] = sep if sep
|
56
54
|
|
55
|
+
CsvHash.read( path, **opts )
|
56
|
+
end
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
parse_csv( _wget!( path ).text,
|
64
|
-
headers: headers )
|
65
|
-
else
|
66
|
-
if headers
|
67
|
-
CsvHash.read( path )
|
68
|
-
else
|
69
|
-
Csv.read( path )
|
70
|
-
end
|
71
|
-
end
|
58
|
+
def parse_csv( str, sep: nil )
|
59
|
+
opts = {}
|
60
|
+
opts[:sep] = sep if sep
|
61
|
+
|
62
|
+
CsvHash.parse( str, **opts )
|
72
63
|
end
|
73
64
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
65
|
+
|
66
|
+
## note - use explicit download for now
|
67
|
+
##
|
68
|
+
def download_csv( url, sep: nil )
|
69
|
+
opts = {}
|
70
|
+
opts[:sep] = sep if sep
|
71
|
+
|
72
|
+
parse_csv( download_text( url ),
|
73
|
+
**opts )
|
80
74
|
end
|
81
75
|
|
82
76
|
|
77
|
+
|
83
78
|
### note: use read_data / parse_data
|
84
79
|
## for alternate shortcut for read_csv / parse_csv w/ headers: false
|
85
80
|
## returning arrays of strings
|
86
81
|
def read_data( path )
|
87
|
-
|
88
|
-
read_data( _wget!( path ).text )
|
89
|
-
else
|
90
|
-
Csv.read( path )
|
91
|
-
end
|
82
|
+
Csv.read( path )
|
92
83
|
end
|
93
84
|
|
94
85
|
def parse_data( str )
|
95
86
|
Csv.parse( str )
|
96
87
|
end
|
97
88
|
|
89
|
+
def download_data( url )
|
90
|
+
parse_data( download_text( url ))
|
91
|
+
end
|
92
|
+
|
98
93
|
|
99
94
|
|
100
95
|
def read_tab( path )
|
101
|
-
|
102
|
-
parse_tab( _wget!( path ).text )
|
103
|
-
else
|
104
|
-
Tab.read( path )
|
105
|
-
end
|
96
|
+
Tab.read( path )
|
106
97
|
end
|
107
98
|
|
108
99
|
def parse_tab( str )
|
109
100
|
Tab.parse( str )
|
110
101
|
end
|
111
102
|
|
103
|
+
def download_tab( url )
|
104
|
+
parse_tab( download_text( url ))
|
105
|
+
end
|
106
|
+
|
107
|
+
|
112
108
|
|
113
109
|
## todo: add symbolize options ???
|
114
110
|
def read_json( path )
|
115
|
-
|
111
|
+
parse_json( read_text( path ))
|
116
112
|
end
|
117
113
|
|
118
114
|
def parse_json( str )
|
119
115
|
JSON.parse( str )
|
120
116
|
end
|
121
117
|
|
118
|
+
def download_json( url )
|
119
|
+
parse_json( download_text( url ))
|
120
|
+
end
|
121
|
+
|
122
122
|
|
123
123
|
### todo/check: use parse_safeyaml or such? (is default anyway?) - why? why not?
|
124
124
|
def read_yaml( path )
|
125
|
-
|
125
|
+
parse_yaml( read_text( path ))
|
126
126
|
end
|
127
127
|
|
128
128
|
def parse_yaml( str )
|
129
129
|
YAML.load( str )
|
130
130
|
end
|
131
131
|
|
132
|
+
def download_yaml( url )
|
133
|
+
parse_yaml( download_text( url ))
|
134
|
+
end
|
135
|
+
|
136
|
+
## keep yml alias - why? why not?
|
137
|
+
alias_method :read_yml, :read_yaml
|
138
|
+
alias_method :parse_yml, :parse_yaml
|
139
|
+
alias_method :download_yml, :download_yaml
|
140
|
+
|
132
141
|
|
133
142
|
def read_ini( path )
|
134
|
-
|
143
|
+
parse_ini( read_text( path ))
|
135
144
|
end
|
136
145
|
|
137
146
|
def parse_ini( str )
|
138
147
|
INI.load( str )
|
139
148
|
end
|
140
149
|
|
150
|
+
def download_ini( url )
|
151
|
+
parse_ini( download_text( url ))
|
152
|
+
end
|
153
|
+
|
141
154
|
alias_method :read_conf, :read_ini
|
142
155
|
alias_method :parse_conf, :parse_ini
|
156
|
+
alias_method :download_conf, :download_ini
|
143
157
|
|
144
158
|
|
145
159
|
|
146
160
|
|
147
161
|
def read_text( path )
|
148
|
-
if _download?( path )
|
149
|
-
_wget!( path ).text
|
150
|
-
else
|
151
162
|
## todo/check: add universal newline mode or such?
|
152
163
|
## e.g. will always convert all
|
153
164
|
## newline variants (\n|\r|\n\r) to "universal" \n only
|
154
165
|
##
|
155
166
|
## add r:bom - why? why not?
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
167
|
+
File.open( path, 'r:utf-8' ) do |f|
|
168
|
+
f.read
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def download_text( url )
|
173
|
+
wget!( url ).text
|
161
174
|
end
|
162
|
-
|
175
|
+
|
176
|
+
alias_method :read_txt, :read_text
|
177
|
+
alias_method :download_txt, :download_text
|
178
|
+
|
163
179
|
|
164
180
|
|
165
181
|
def read_blob( path )
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
blob = File.open( path, 'rb' ) do |f|
|
170
|
-
f.read
|
171
|
-
end
|
172
|
-
blob
|
173
|
-
end
|
182
|
+
File.open( path, 'rb' ) do |f|
|
183
|
+
f.read
|
184
|
+
end
|
174
185
|
end
|
175
|
-
alias_method :read_binary, :read_blob
|
176
|
-
alias_method :read_bin, :read_blob
|
186
|
+
## alias_method :read_binary, :read_blob
|
187
|
+
## alias_method :read_bin, :read_blob
|
177
188
|
|
189
|
+
def download_blob( url )
|
190
|
+
wget!( url ).blob
|
191
|
+
end
|
192
|
+
## alias_method :download_binary, :download_blob
|
193
|
+
## alias_method :download_bin, :download_blob
|
178
194
|
|
179
195
|
|
180
196
|
|
@@ -191,10 +207,14 @@ def parse_lines( str )
|
|
191
207
|
str.lines
|
192
208
|
end
|
193
209
|
|
210
|
+
def download_lines( url )
|
211
|
+
parse_lines( download_text( url ))
|
212
|
+
end
|
213
|
+
|
194
214
|
|
195
215
|
|
196
216
|
def read_env( path )
|
197
|
-
|
217
|
+
parse_env( read_text( path ))
|
198
218
|
end
|
199
219
|
|
200
220
|
def parse_env( str )
|
@@ -251,8 +271,8 @@ def write_blob( path, blob )
|
|
251
271
|
f.write( blob )
|
252
272
|
end
|
253
273
|
end
|
254
|
-
alias_method :write_binary, :write_blob
|
255
|
-
alias_method :write_bin, :write_blob
|
274
|
+
# alias_method :write_binary, :write_blob
|
275
|
+
# alias_method :write_bin, :write_blob
|
256
276
|
|
257
277
|
|
258
278
|
def write_text( path, text )
|
@@ -274,20 +294,20 @@ alias_method :write_txt, :write_text
|
|
274
294
|
#
|
275
295
|
# note:
|
276
296
|
# for now write_csv expects array of string arrays
|
277
|
-
# does NOT support array of hashes for now
|
297
|
+
# does NOT support array of hashes for now
|
278
298
|
|
279
299
|
def write_csv( path, recs, headers: nil )
|
280
300
|
dirname = File.dirname( path )
|
281
301
|
FileUtils.mkdir_p( dirname ) unless Dir.exist?( dirname )
|
282
302
|
|
283
303
|
File.open( path, 'w:utf-8' ) do |f|
|
284
|
-
if headers
|
304
|
+
if headers
|
285
305
|
f.write( headers.join(',')) ## e.g. Date,Team 1,FT,HT,Team 2
|
286
306
|
f.write( "\n" )
|
287
|
-
end
|
307
|
+
end
|
288
308
|
|
289
309
|
recs.each do |values|
|
290
|
-
## quote values that incl. a comma
|
310
|
+
## quote values that incl. a comma
|
291
311
|
## todo/fix - add more escape/quote checks - why? why not?
|
292
312
|
## check how other csv libs handle value generation
|
293
313
|
buf = values.map do |value|
|
@@ -297,10 +317,10 @@ def write_csv( path, recs, headers: nil )
|
|
297
317
|
value
|
298
318
|
end
|
299
319
|
end.join( ',' )
|
300
|
-
|
320
|
+
|
301
321
|
f.write( buf )
|
302
322
|
f.write( "\n" )
|
303
|
-
end
|
323
|
+
end
|
304
324
|
end
|
305
325
|
end
|
306
326
|
|
@@ -309,16 +329,13 @@ end
|
|
309
329
|
######
|
310
330
|
# world wide web (www) support
|
311
331
|
|
312
|
-
def wget( url, **
|
313
|
-
Webclient.get( url, **
|
332
|
+
def wget( url, **opts )
|
333
|
+
Webclient.get( url, **opts )
|
314
334
|
end
|
315
335
|
## add alias www_get or web_get - why? why not?
|
316
336
|
|
317
|
-
|
318
|
-
|
319
|
-
## private helper - make public -why? why not?
|
320
|
-
def _wget!( url, **kwargs )
|
321
|
-
res = Webclient.get( url, **kwargs )
|
337
|
+
def wget!( url, **opts )
|
338
|
+
res = Webclient.get( url, **opts )
|
322
339
|
|
323
340
|
## check/todo - use a different exception/error - keep RuntimeError - why? why not?
|
324
341
|
raise RuntimeError, "HTTP #{res.status.code} - #{res.status.message}" if res.status.nok?
|
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.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: csvreader
|
@@ -101,7 +101,7 @@ dependencies:
|
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '4.1'
|
103
103
|
description: cocos (code commons) - auto-include quick-starter prelude & prolog
|
104
|
-
email:
|
104
|
+
email: gerald.bauer@gmail.com
|
105
105
|
executables: []
|
106
106
|
extensions: []
|
107
107
|
extra_rdoc_files:
|