cocos 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cocos/version.rb +1 -1
  3. data/lib/cocos.rb +69 -17
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed017038dd37ce27a71bb2835900c893dc916643e1f07e3809a18eca3f626265
4
- data.tar.gz: 77f8a74da6add1f4af968364c3eecfbae7cb1dfd88bce89bb04490ad3932df44
3
+ metadata.gz: 40d870d3371a969672ba3e6b61dfb5cfbfae18809fa2edb96c8a3dbdfa44f1e8
4
+ data.tar.gz: f811adb7be939ff1dd90108fe16bf036f45e40540cbbff81fb7d20d6591c1426
5
5
  SHA512:
6
- metadata.gz: c74889afd4f26afd75e8bcd306920f916646787cf3a85e3d94e2e67b0aed81bea4747c7e924d0dde40c2aa22661a61eed59c656ca1f57842ffd4d6f9099ae00b
7
- data.tar.gz: f25f050d937978cf344530b6f347716f79f137b1e467518be2c5d506a39eedbe7f5bf16163047685cf18d4e34d7cf501cc200db6b1c876e0406b35f4d0968edc
6
+ metadata.gz: b504140b89069be5896ab2028263e191475d5d92423fc6df4be069523c2b037b0c28830ec0fa89426e0212007044344ed4c849345e016d12c2c0832575b85920
7
+ data.tar.gz: 1b5a4741a03b48740fb4868bf54c054382dbee3a3f7b7cca243d2393c88cc0c6cb5b5d75e593d5c3bdec075d3df32a714eb4f7ec861572dfd9c3e4a2278f9548
data/lib/cocos/version.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  module Cocos
3
3
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
4
4
  MINOR = 2
5
- PATCH = 0
5
+ PATCH = 1
6
6
  VERSION = [MAJOR,MINOR,PATCH].join('.')
7
7
 
8
8
  def self.version
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
- if headers
47
- CsvHash.read( path )
61
+
62
+ if _download?( path )
63
+ parse_csv( _wget!( path ).text,
64
+ headers: headers )
48
65
  else
49
- Csv.read( path )
50
- end
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
- Csv.read( path )
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
- Tab.read( path )
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
- JSON.parse( read_text( path ))
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
- YAML.load( read_text( path ))
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
- INI.load( read_text( path ))
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
- blob = File.open( path, 'rb' ) do |f|
131
- f.read
132
- end
133
- blob
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
- lines = File.open( path, 'r:utf-8' ) do |f|
146
- f.readlines
147
- end
148
- lines
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.0
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-22 00:00:00.000000000 Z
11
+ date: 2022-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: csvreader