exobasic 0.1.0 → 0.1.2

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: 804b273f3d2c35dbf8f0ff3cde48e05830bd6baf75bc1e448b60b433b30daa29
4
- data.tar.gz: 46a64b7e4b1dce72249e72e1992f673a577e096b8d568b8eb5696087a8cdceae
3
+ metadata.gz: 7188dc6fd9369870387ec25111420f691d07b53319554db7cc177f17beeb17b9
4
+ data.tar.gz: f818440bebd8d174f594fde794a398591f3e32112f8915f0de29f3ad8ad4d61f
5
5
  SHA512:
6
- metadata.gz: 66a06c15c4ea3c3f1862134f3e4a76ab8bf800002d2e35f97a297d66e88e82498b59070e4153001f16afcf4e8de030f3c682768fecfdbd01049552ed5d19401e
7
- data.tar.gz: c5b9e1be628bb51eedf24fa6374eef6301a82549fa389339ef70c4bbe7749ff1168bd95f7a942945d02b3c4be884231fc7e33a89de9e030c7eb6a7eeee893604
6
+ metadata.gz: d0676aa46835d71fea972a317288ec80f04dd90c0699ba5019293d86b087a7070c5eea208255235831c5f57fa9fd471807018af7a848d5804b3ca34a0d137073
7
+ data.tar.gz: 7188b9356f8bf78c23a5a97a852b38e6ef2fb59b3bbef95dc9550ae6e5e503fa2afae0e2dd68c64c75d41d117065cccb8c9cace135b2d4f26ee37de6e2134319
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  BasicHelpers: This gem provides basic helpers for a Ruby project.
4
4
 
5
- - data: DFS
5
+ - data: DFS, CSV
6
6
  - encryption: ECDSA, RSA, HMAC, Password
7
7
  - http: JSON HTTP client
8
8
  - stats: Average counters
@@ -18,6 +18,14 @@ BasicHelpers: This gem provides basic helpers for a Ruby project.
18
18
 
19
19
  ## Getting started
20
20
 
21
+ `bundle`
22
+
23
+ `rake build`
24
+
25
+ `gem push [GEM.gem]`
26
+
27
+
21
28
  ### Requirements
22
29
 
23
30
  - Ruby 2.5+
31
+ - BCrypt 3.1.12
@@ -0,0 +1,74 @@
1
+ module ExoBasic
2
+ class CSV
3
+ def self.str_tok(str, tok_char)
4
+ str.strip.split(tok_char)
5
+ end
6
+
7
+ def self.mk_hdr(elements)
8
+ elements.map { |i| i.downcase }
9
+ end
10
+
11
+ def self.mk_rec(hdr, elements)
12
+ hdr.zip(elements)
13
+ .map do |pair|
14
+ k = pair[0]
15
+ v = pair[1]
16
+ if !v.nil?
17
+ v = v.strip
18
+ end
19
+
20
+ [k, v]
21
+ end
22
+ .to_h
23
+ end
24
+
25
+ def self.append_file_info(rec, filename, line)
26
+ rec['file'] = filename
27
+ rec['line_no'] = line + 1
28
+ end
29
+
30
+ def self.load_csv_file_as_list(csv_file,
31
+ tok_char=',', with_file_info=false)
32
+ fields = []
33
+ records = []
34
+ File.foreach(csv_file).with_index do |line, line_num|
35
+ pieces = CSV.str_tok(line, tok_char)
36
+ if line_num == 0
37
+ fields = CSV.mk_hdr(pieces)
38
+ else
39
+ record = CSV.mk_rec(fields, pieces)
40
+ if with_file_info
41
+ CSV.append_file_info(record, csv_file, line_num)
42
+ end
43
+
44
+ records.push(record)
45
+ end
46
+ end
47
+
48
+ records
49
+ end
50
+
51
+ def self.load_csv_file_as_hash(csv_file,
52
+ tok_char=',', with_file_info=false)
53
+ fields = []
54
+ records = {}
55
+ File.foreach(csv_file).with_index do |line, line_num|
56
+ pieces = CSV.str_tok(line, tok_char)
57
+ if line_num == 0
58
+ fields = CSV.mk_hdr(pieces)
59
+ else
60
+ record = CSV.mk_rec(fields, pieces)
61
+ record['id'] = pieces[0]
62
+ if with_file_info
63
+ CSV.append_file_info(record, csv_file, line_num)
64
+ end
65
+
66
+ records[record['id']] = record
67
+ end
68
+ end
69
+
70
+ records
71
+ end
72
+
73
+ end
74
+ end
@@ -47,7 +47,7 @@ module ExoBasic
47
47
  f = Settings::DEFAULT_FILENAME
48
48
  end
49
49
 
50
- if File.exists?(f)
50
+ if File.exist?(f)
51
51
  js = JSON.load(
52
52
  File.readlines(f)
53
53
  .select { |line| !line.strip.start_with?('//') }
@@ -1,3 +1,3 @@
1
1
  module ExoBasic
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/exobasic.rb CHANGED
@@ -3,6 +3,7 @@ require 'exobasic/settings'
3
3
  require 'exobasic/str_helpers'
4
4
 
5
5
  require 'exobasic/data/dfs'
6
+ require 'exobasic/data/csv'
6
7
 
7
8
  require 'exobasic/encrypt/ecdsa_keys'
8
9
  require 'exobasic/encrypt/hmac_keys'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exobasic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dionysios Kakolyris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-18 00:00:00.000000000 Z
11
+ date: 2022-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bcrypt
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 3.1.12
19
+ version: 3.1.18
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 3.1.12
26
+ version: 3.1.18
27
27
  description: Exotic Basic Helpers
28
28
  email:
29
29
  - contact@exotic.industries
@@ -33,6 +33,7 @@ extra_rdoc_files: []
33
33
  files:
34
34
  - README.md
35
35
  - lib/exobasic.rb
36
+ - lib/exobasic/data/csv.rb
36
37
  - lib/exobasic/data/dfs.rb
37
38
  - lib/exobasic/encrypt/ecdsa_keys.rb
38
39
  - lib/exobasic/encrypt/hmac_keys.rb