cocos 0.0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0c0c91a32d9421aa68462fe03987ffd9c0e7ec6b8ef56acb4d3ed2b8f148ed6d
4
- data.tar.gz: a7fa42e171cd6480f264cadeb196b287f2a9f46af1b0fa4a284295fee030bfdc
3
+ metadata.gz: ed017038dd37ce27a71bb2835900c893dc916643e1f07e3809a18eca3f626265
4
+ data.tar.gz: 77f8a74da6add1f4af968364c3eecfbae7cb1dfd88bce89bb04490ad3932df44
5
5
  SHA512:
6
- metadata.gz: 5aa60909fb45f952871b8a7f0fb1afac09bbf73bda390d3f1a1ca51a4f91454621dffc44cad32552ec5ce3d9f731168b7a659a3529d564650b3902fc57eac07f
7
- data.tar.gz: 0ee9fde4d05b4a82101cc023e01833b1a946579fbf5ec321076e6247e1b1387516830e847a0bccc4070f1c34772dd53d47f7e7029e06fd300fcf8a5c9e7c6413
6
+ metadata.gz: c74889afd4f26afd75e8bcd306920f916646787cf3a85e3d94e2e67b0aed81bea4747c7e924d0dde40c2aa22661a61eed59c656ca1f57842ffd4d6f9099ae00b
7
+ data.tar.gz: f25f050d937978cf344530b6f347716f79f137b1e467518be2c5d506a39eedbe7f5bf16163047685cf18d4e34d7cf501cc200db6b1c876e0406b35f4d0968edc
data/LICENSE.md ADDED
@@ -0,0 +1,116 @@
1
+ CC0 1.0 Universal
2
+
3
+ Statement of Purpose
4
+
5
+ The laws of most jurisdictions throughout the world automatically confer
6
+ exclusive Copyright and Related Rights (defined below) upon the creator and
7
+ subsequent owner(s) (each and all, an "owner") of an original work of
8
+ authorship and/or a database (each, a "Work").
9
+
10
+ Certain owners wish to permanently relinquish those rights to a Work for the
11
+ purpose of contributing to a commons of creative, cultural and scientific
12
+ works ("Commons") that the public can reliably and without fear of later
13
+ claims of infringement build upon, modify, incorporate in other works, reuse
14
+ and redistribute as freely as possible in any form whatsoever and for any
15
+ purposes, including without limitation commercial purposes. These owners may
16
+ contribute to the Commons to promote the ideal of a free culture and the
17
+ further production of creative, cultural and scientific works, or to gain
18
+ reputation or greater distribution for their Work in part through the use and
19
+ efforts of others.
20
+
21
+ For these and/or other purposes and motivations, and without any expectation
22
+ of additional consideration or compensation, the person associating CC0 with a
23
+ Work (the "Affirmer"), to the extent that he or she is an owner of Copyright
24
+ and Related Rights in the Work, voluntarily elects to apply CC0 to the Work
25
+ and publicly distribute the Work under its terms, with knowledge of his or her
26
+ Copyright and Related Rights in the Work and the meaning and intended legal
27
+ effect of CC0 on those rights.
28
+
29
+ 1. Copyright and Related Rights. A Work made available under CC0 may be
30
+ protected by copyright and related or neighboring rights ("Copyright and
31
+ Related Rights"). Copyright and Related Rights include, but are not limited
32
+ to, the following:
33
+
34
+ i. the right to reproduce, adapt, distribute, perform, display, communicate,
35
+ and translate a Work;
36
+
37
+ ii. moral rights retained by the original author(s) and/or performer(s);
38
+
39
+ iii. publicity and privacy rights pertaining to a person's image or likeness
40
+ depicted in a Work;
41
+
42
+ iv. rights protecting against unfair competition in regards to a Work,
43
+ subject to the limitations in paragraph 4(a), below;
44
+
45
+ v. rights protecting the extraction, dissemination, use and reuse of data in
46
+ a Work;
47
+
48
+ vi. database rights (such as those arising under Directive 96/9/EC of the
49
+ European Parliament and of the Council of 11 March 1996 on the legal
50
+ protection of databases, and under any national implementation thereof,
51
+ including any amended or successor version of such directive); and
52
+
53
+ vii. other similar, equivalent or corresponding rights throughout the world
54
+ based on applicable law or treaty, and any national implementations thereof.
55
+
56
+ 2. Waiver. To the greatest extent permitted by, but not in contravention of,
57
+ applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
58
+ unconditionally waives, abandons, and surrenders all of Affirmer's Copyright
59
+ and Related Rights and associated claims and causes of action, whether now
60
+ known or unknown (including existing as well as future claims and causes of
61
+ action), in the Work (i) in all territories worldwide, (ii) for the maximum
62
+ duration provided by applicable law or treaty (including future time
63
+ extensions), (iii) in any current or future medium and for any number of
64
+ copies, and (iv) for any purpose whatsoever, including without limitation
65
+ commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes
66
+ the Waiver for the benefit of each member of the public at large and to the
67
+ detriment of Affirmer's heirs and successors, fully intending that such Waiver
68
+ shall not be subject to revocation, rescission, cancellation, termination, or
69
+ any other legal or equitable action to disrupt the quiet enjoyment of the Work
70
+ by the public as contemplated by Affirmer's express Statement of Purpose.
71
+
72
+ 3. Public License Fallback. Should any part of the Waiver for any reason be
73
+ judged legally invalid or ineffective under applicable law, then the Waiver
74
+ shall be preserved to the maximum extent permitted taking into account
75
+ Affirmer's express Statement of Purpose. In addition, to the extent the Waiver
76
+ is so judged Affirmer hereby grants to each affected person a royalty-free,
77
+ non transferable, non sublicensable, non exclusive, irrevocable and
78
+ unconditional license to exercise Affirmer's Copyright and Related Rights in
79
+ the Work (i) in all territories worldwide, (ii) for the maximum duration
80
+ provided by applicable law or treaty (including future time extensions), (iii)
81
+ in any current or future medium and for any number of copies, and (iv) for any
82
+ purpose whatsoever, including without limitation commercial, advertising or
83
+ promotional purposes (the "License"). The License shall be deemed effective as
84
+ of the date CC0 was applied by Affirmer to the Work. Should any part of the
85
+ License for any reason be judged legally invalid or ineffective under
86
+ applicable law, such partial invalidity or ineffectiveness shall not
87
+ invalidate the remainder of the License, and in such case Affirmer hereby
88
+ affirms that he or she will not (i) exercise any of his or her remaining
89
+ Copyright and Related Rights in the Work or (ii) assert any associated claims
90
+ and causes of action with respect to the Work, in either case contrary to
91
+ Affirmer's express Statement of Purpose.
92
+
93
+ 4. Limitations and Disclaimers.
94
+
95
+ a. No trademark or patent rights held by Affirmer are waived, abandoned,
96
+ surrendered, licensed or otherwise affected by this document.
97
+
98
+ b. Affirmer offers the Work as-is and makes no representations or warranties
99
+ of any kind concerning the Work, express, implied, statutory or otherwise,
100
+ including without limitation warranties of title, merchantability, fitness
101
+ for a particular purpose, non infringement, or the absence of latent or
102
+ other defects, accuracy, or the present or absence of errors, whether or not
103
+ discoverable, all to the greatest extent permissible under applicable law.
104
+
105
+ c. Affirmer disclaims responsibility for clearing rights of other persons
106
+ that may apply to the Work or any use thereof, including without limitation
107
+ any person's Copyright and Related Rights in the Work. Further, Affirmer
108
+ disclaims responsibility for obtaining any necessary consents, permissions
109
+ or other rights required for any use of the Work.
110
+
111
+ d. Affirmer understands and acknowledges that Creative Commons is not a
112
+ party to this document and has no duty or obligation with respect to this
113
+ CC0 or use of the Work.
114
+
115
+ For more information, please see
116
+ <http://creativecommons.org/publicdomain/zero/1.0/>
data/Manifest.txt CHANGED
@@ -1,4 +1,5 @@
1
1
  CHANGELOG.md
2
+ LICENSE.md
2
3
  Manifest.txt
3
4
  README.md
4
5
  Rakefile
data/README.md CHANGED
@@ -1,17 +1,140 @@
1
- # cocos (code commons) - auto-incude quick-starter prelude & prolog
1
+ # cocos (code commons) - auto-include quick-starter prelude & prolog
2
2
 
3
3
 
4
- * home :: [github.com/rubycocos/cococs](https://github.com/rubycocos/cococs)
5
- * bugs :: [github.com/rubycocos/cococs/issues](https://github.com/rubycocos/cococs/issues)
4
+ * home :: [github.com/rubycocos/cocos](https://github.com/rubycocos/cocos)
5
+ * bugs :: [github.com/rubycocos/cocos/issues](https://github.com/rubycocos/cocos/issues)
6
6
  * gem :: [rubygems.org/gems/cocos](https://rubygems.org/gems/cocos)
7
7
  * rdoc :: [rubydoc.info/gems/cocos](http://rubydoc.info/gems/cocos)
8
8
 
9
9
 
10
10
 
11
+ ## Intro - Why?
12
+
13
+
14
+ **Reason No. 1**
15
+
16
+ After starting of too many scripts (hundreds?) with
17
+ adding more and always repeating the same dozen modules with require e.g.:
18
+
19
+ ``` ruby
20
+ require 'pp'
21
+ require 'time'
22
+ require 'date'
23
+ require 'json'
24
+ require 'yaml'
25
+ require 'base64'
26
+ require 'fileutils'
27
+
28
+ require 'uri'
29
+ require 'net/http'
30
+ require 'net/https'
31
+
32
+ ...
33
+ ```
34
+
35
+ why not use a more "inclusive" prelude & prolog and
36
+ replace the above with a one-liner:
37
+
38
+ ``` ruby
39
+ require 'cocos' # auto-include code commons quick-starter prelude & prolog
40
+ ```
41
+
42
+
43
+ **Reason No. 2**
44
+
45
+ After reading too many text files in utf-8 and always repeating the same open / read and code block dance e.g.:
46
+
47
+ ``` ruby
48
+ txt = File.read( "history.txt" )
49
+ # sorry - will NOT guarantee unicode utf8-encoding
50
+ # (e.g. on microsoft windows it is ISO Code Page (CP-1252
51
+ # or something - depending on your locale/culture/language)
52
+
53
+ txt = File.open( "history.txt", "r:utf-8" ) do |f|
54
+ f.read
55
+ end
56
+ ```
57
+
58
+ Or after reading and parsing too many json files
59
+ (by default always required utf-8 encoding)
60
+ and always repeating the same open / read and code block dance
61
+ again and again e.g.:
62
+
63
+ ``` ruby
64
+ txt = File.open( "history.json", "r:utf-8" ) do |f|
65
+ f.read
66
+ end
67
+ data = JSON.parse( txt )
68
+ ```
69
+
70
+ Why not use read convenience / short-cut helpers such as:
71
+
72
+ ``` ruby
73
+ txt = read_txt( "history.txt" )
74
+ data = read_json( "history.json" )
75
+ ```
76
+
77
+
78
+ And so on.
79
+
80
+
81
+
82
+
83
+
11
84
  ## Usage
12
85
 
86
+ ### Read / Parse
87
+
88
+ _Read / parse convenience short-cut helpers_
89
+
90
+ `read_blob( path )` <br>
91
+ also known as `read_binary` or `read_bin`
92
+
93
+
94
+ `read_text( path )` <br>
95
+ also known as `read_txt`
96
+
97
+
98
+ `read_lines( path )`
99
+
100
+
101
+
102
+ `read_json( path )` / `parse_json( str )`
103
+
104
+
105
+ `read_yaml( path )` / `parse_yaml( str )`
106
+
107
+
108
+ `read_csv( path, headers: true )` / `parse_csv( str, headers: true )`
109
+
110
+ note: comma-separated values (.csv) reading & parsing service
111
+ brought to you by the [**csvreader library / gem »**](https://github.com/rubycocos/csvreader/tree/master/csvreader)
112
+
113
+
114
+ `read_data( path )` / `parse_data( str )`
115
+
116
+ note: alternate shortcut / alias for `read_csv( path, headers: false )` / `parse_csv( str, headers: false )`
117
+
118
+
119
+
120
+
121
+ `read_tab( path )` / `parse_tab( str )`
122
+
123
+ note: tabulator (`\t`)-separated values (.tab) reading & parsing service
124
+ brought to you by the [**tabreader library / gem »**](https://github.com/rubycocos/csvreader/tree/master/tabreader)
125
+
126
+
127
+
128
+
129
+ `read_ini( path )` / `parse_ini( str )` <br>
130
+ also known as `read_conf / parse_conf`
131
+
132
+ note: ini / conf(ig) reading & parsing service
133
+ brought to you by the [**iniparser library / gem »**](https://github.com/rubycocos/core/tree/master/iniparser)
134
+
135
+
13
136
 
14
- To be done
137
+ That's it for now.
15
138
 
16
139
 
17
140
 
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ Hoe.spec 'cocos' do
6
6
 
7
7
  self.version = Cocos::VERSION
8
8
 
9
- self.summary = "cocos (code commons) - auto-incude quick-starter prelude & prolog"
9
+ self.summary = "cocos (code commons) - auto-include quick-starter prelude & prolog"
10
10
  self.description = summary
11
11
 
12
12
  self.urls = { home: 'https://github.com/rubycocos/cocos' }
@@ -20,7 +20,12 @@ Hoe.spec 'cocos' do
20
20
 
21
21
  self.licenses = ['Public Domain']
22
22
 
23
- self.extra_deps = []
23
+ self.extra_deps = [
24
+ ['csvreader', '>= 1.2.5'],
25
+ ['tabreader', '>= 1.0.1'],
26
+ ['iniparser', '>= 1.0.1'],
27
+ ['webclient', '>= 0.2.2'],
28
+ ]
24
29
 
25
30
  self.spec_extras = {
26
31
  required_ruby_version: '>= 2.2.2'
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 = 0
5
- PATCH = 1
4
+ MINOR = 2
5
+ PATCH = 0
6
6
  VERSION = [MAJOR,MINOR,PATCH].join('.')
7
7
 
8
8
  def self.version
data/lib/cocos.rb CHANGED
@@ -6,22 +6,217 @@ require 'time'
6
6
  require 'date'
7
7
  require 'json'
8
8
  require 'yaml'
9
+ require 'base64' ## e.g. Base64.decode64,Base64.encode64,...
9
10
  require 'fileutils'
10
11
 
11
12
  require 'uri'
12
13
  require 'net/http'
13
14
  require 'net/https'
14
-
15
+ require 'cgi'
15
16
 
16
17
  require 'optparse' ## used by monofile (built-in test/debug) command line tool
17
18
 
18
19
 
20
+ ###
21
+ # 3rd party gems
22
+ require 'csvreader'
23
+ require 'tabreader'
24
+ require 'iniparser'
25
+
26
+ require 'webclient'
27
+
28
+
19
29
 
20
30
  #####################
21
31
  # our own code
22
32
  require 'cocos/version' # note: let version always go first
23
33
 
24
34
 
35
+ ###
36
+ ## read/parse convenience/helper shortcuts
37
+
38
+
39
+ module Kernel
40
+
41
+
42
+
43
+ ## todo: add symbolize options a la read_json
44
+ ## add sep options
45
+ def read_csv( path, headers: true )
46
+ if headers
47
+ CsvHash.read( path )
48
+ else
49
+ Csv.read( path )
50
+ end
51
+ end
52
+
53
+ def parse_csv( str, headers: true )
54
+ if headers
55
+ CsvHash.parse( str )
56
+ else
57
+ Csv.parse( str )
58
+ end
59
+ end
60
+
61
+
62
+ ### note: use read_data / parse_data
63
+ ## for alternate shortcut for read_csv / parse_csv w/ headers: false
64
+ ## returning arrays of strings
65
+ def read_data( path )
66
+ Csv.read( path )
67
+ end
68
+
69
+ def parse_data( str )
70
+ Csv.parse( str )
71
+ end
72
+
73
+
74
+
75
+ def read_tab( path )
76
+ Tab.read( path )
77
+ end
78
+
79
+ def parse_tab( str )
80
+ Tab.parse( str )
81
+ end
82
+
83
+
84
+ ## todo: add symbolize options ???
85
+ def read_json( path )
86
+ JSON.parse( read_text( path ))
87
+ end
88
+
89
+ def parse_json( str )
90
+ JSON.parse( str )
91
+ end
92
+
93
+ ### todo/check: use parse_safeyaml or such? (is default anyway?) - why? why not?
94
+ def read_yaml( path )
95
+ YAML.load( read_text( path ))
96
+ end
97
+
98
+ def parse_yaml( str )
99
+ YAML.load( str )
100
+ end
101
+
102
+
103
+ def read_ini( path )
104
+ INI.load( read_text( path ))
105
+ end
106
+
107
+ def parse_ini( str )
108
+ INI.load( str )
109
+ end
110
+
111
+ alias_method :read_conf, :read_ini
112
+ alias_method :parse_conf, :parse_ini
113
+
114
+
115
+
116
+
117
+ def read_text( path )
118
+ ## todo/check: add universal newline mode or such?
119
+ ## e.g. will always convert all
120
+ ## newline variants (\n|\r|\n\r) to "universal" \n only
121
+ txt = File.open( path, 'r:utf-8' ) do |f|
122
+ f.read
123
+ end
124
+ txt
125
+ end
126
+ alias_method :read_txt, :read_text
127
+
128
+
129
+ def read_blob( path )
130
+ blob = File.open( path, 'rb' ) do |f|
131
+ f.read
132
+ end
133
+ blob
134
+ end
135
+ alias_method :read_binary, :read_blob
136
+ alias_method :read_bin, :read_blob
137
+
138
+
139
+
140
+
141
+ ## todo/check: remove \n (or\r or \r\n) from line
142
+ ## ruby (by default) keeps the newline - follow tradition? why? why not?
143
+ ##
144
+ def read_lines( path )
145
+ lines = File.open( path, 'r:utf-8' ) do |f|
146
+ f.readlines
147
+ end
148
+ lines
149
+ end
150
+
151
+
152
+
153
+
154
+ ######
155
+ # add writers
156
+
157
+ def write_json( path, data )
158
+ ###
159
+ ## todo/check: check if data is Webclient.Response?
160
+ ## if yes use res.json - why? why not?
161
+
162
+ dirname = File.dirname( path )
163
+ FileUtils.mkdir_p( dirname ) unless Dir.exist?( dirname )
164
+
165
+ ## note: pretty print/reformat json
166
+ File.open( path, "w:utf-8" ) do |f|
167
+ f.write( JSON.pretty_generate( data ))
168
+ end
169
+ end
170
+
171
+
172
+ def write_blob( path, blob )
173
+ ###
174
+ ## todo/check: check if data is Webclient.Response?
175
+ ## if yes use res.blob/body - why? why not?
176
+
177
+ dirname = File.dirname( path )
178
+ FileUtils.mkdir_p( dirname ) unless Dir.exist?( dirname )
179
+
180
+ File.open( path, "wb" ) do |f|
181
+ f.write( blob )
182
+ end
183
+ end
184
+ alias_method :write_binary, :write_blob
185
+ alias_method :write_bin, :write_blob
186
+
187
+
188
+ def write_text( path, text )
189
+ ###
190
+ ## todo/check: check if data is Webclient.Response?
191
+ ## if yes use res.text - why? why not?
192
+
193
+ dirname = File.dirname( path )
194
+ FileUtils.mkdir_p( dirname ) unless Dir.exist?( dirname )
195
+
196
+ File.open( path, "w:utf-8" ) do |f|
197
+ f.write( text )
198
+ end
199
+ end
200
+ alias_method :write_txt, :write_text
201
+
202
+
203
+
204
+ ######
205
+ # world wide web (www) support
206
+
207
+ def wget( url, **kwargs )
208
+ Webclient.get( url, **kwargs )
209
+ end
210
+ ## add alias www_get or web_get - why? why not?
211
+
212
+
213
+
214
+ end # module Kernel
215
+
216
+
217
+
218
+
219
+
25
220
  ####
26
221
  # convenience alias (use plural or singual)
27
222
  Coco = Cocos
metadata CHANGED
@@ -1,15 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.2.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: 2022-08-01 00:00:00.000000000 Z
11
+ date: 2022-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: csvreader
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.2.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.2.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: tabreader
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: iniparser
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: webclient
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 0.2.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 0.2.2
13
69
  - !ruby/object:Gem::Dependency
14
70
  name: rdoc
15
71
  requirement: !ruby/object:Gem::Requirement
@@ -44,16 +100,18 @@ dependencies:
44
100
  - - "~>"
45
101
  - !ruby/object:Gem::Version
46
102
  version: '3.23'
47
- description: cocos (code commons) - auto-incude quick-starter prelude & prolog
103
+ description: cocos (code commons) - auto-include quick-starter prelude & prolog
48
104
  email: opensport@googlegroups.com
49
105
  executables: []
50
106
  extensions: []
51
107
  extra_rdoc_files:
52
108
  - CHANGELOG.md
109
+ - LICENSE.md
53
110
  - Manifest.txt
54
111
  - README.md
55
112
  files:
56
113
  - CHANGELOG.md
114
+ - LICENSE.md
57
115
  - Manifest.txt
58
116
  - README.md
59
117
  - Rakefile
@@ -83,5 +141,5 @@ requirements: []
83
141
  rubygems_version: 3.3.7
84
142
  signing_key:
85
143
  specification_version: 4
86
- summary: cocos (code commons) - auto-incude quick-starter prelude & prolog
144
+ summary: cocos (code commons) - auto-include quick-starter prelude & prolog
87
145
  test_files: []