zarby 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3979c8c12db4aaa03312129567f9836f09fd4ef4c1288b4f6737e3b030e4aae7
4
+ data.tar.gz: 265f5cf58138de71a8a4cd977bc7222a78c20c6cecd5346744c5561ecca41a62
5
+ SHA512:
6
+ metadata.gz: 32832c0c4d326ca5bb0ec5fbee10b05cacc01712f178cb1c8aacb3e9148571e0b6a3a7389c744572c46c25ba1a783bf6852b8c1a672708995885ded6ecbfe5d4
7
+ data.tar.gz: 6fe7d3c06a98f18dc921f9dadc9a272e0389cb341f567df6f1d2bf6222555fac02fe44e4d60a83ffca8e56f5dfb08b6fd06f547d6210772d4ffa20c3b27bb04f
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 VianneySonneville
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Zarby
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/zarby`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/VianneySonneville/zarby.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
data/lib/zarby/csv.rb ADDED
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zarby
4
+ class NoColSepDetected < StandardError; end
5
+
6
+ class Csv
7
+ COMMON_DELIMITERS = ['","', '";"', '":"', '"|"'].freeze
8
+
9
+ def initialize(content:)
10
+ @content = content
11
+ end
12
+
13
+ def self.detect_separator(content)
14
+ new(content: content).detect_separator
15
+ end
16
+
17
+ def detect_separator
18
+ valid? ? delimiters[0][0][1] : raise(Zarby::NoColSepDetected)
19
+ end
20
+
21
+ private
22
+
23
+ def valid?
24
+ !delimiters.collect(&:last).reduce(:+).zero?
25
+ end
26
+
27
+ # delimiters #=> [["\"|\"", 54], ["\",\"", 0], ["\";\"", 0]]
28
+ # delimiters[0] #=> ["\";\"", 54]
29
+ # delimiters[0][0] #=> "\",\""
30
+ # delimiters[0][0][1] #=> ";"
31
+ def delimiters
32
+ @delimiters ||= COMMON_DELIMITERS.inject({}, &count).sort(&most_found)
33
+ end
34
+
35
+ def most_found
36
+ ->(a, b) { b[1] <=> a[1] }
37
+ end
38
+
39
+ def count
40
+ lambda { |hash, delimiter|
41
+ hash[delimiter] = @content.count(delimiter)
42
+ hash
43
+ }
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zarby
4
+ VERSION = "0.1.0"
5
+ end
data/lib/zarby.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'zarby/version'
4
+ require_relative 'zarby/csv'
5
+
6
+ module Zarby
7
+ class ZarbyError < StandardError; end
8
+ end
data/sig/zarby.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Zarby
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
data/zarby.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/zarby/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "zarby"
7
+ spec.version = Zarby::VERSION
8
+ spec.authors = ["vianney.sonneville"]
9
+ spec.email = ["vianneysonneville4@gmail.com"]
10
+
11
+ spec.summary = "String encoding and decoding with Ruby."
12
+ # spec.description = "TODO: Write a longer description or delete this line."
13
+ spec.homepage = "https://rubygems.org/gems/zarby"
14
+ spec.required_ruby_version = ">= 2.6.0"
15
+ spec.licenses = ['MIT']
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = spec.homepage
20
+ spec.metadata["changelog_uri"] = "https://github.com/VianneySonneville/zarby/blob/main/CHANGELOG.md"
21
+ spec.metadata["github_repo"] = "git@github.com:VianneySonneville/zarby.git"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (File.expand_path(f) == __FILE__) ||
28
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
29
+ end
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ # Uncomment to register a new dependency of your gem
36
+ # For more information and examples about making a new gem, check out our
37
+ # guide at: https://bundler.io/guides/creating_gem.html
38
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zarby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - vianney.sonneville
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-10-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - vianneysonneville4@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - LICENSE
21
+ - README.md
22
+ - Rakefile
23
+ - lib/zarby.rb
24
+ - lib/zarby/csv.rb
25
+ - lib/zarby/version.rb
26
+ - sig/zarby.rbs
27
+ - zarby.gemspec
28
+ homepage: https://rubygems.org/gems/zarby
29
+ licenses:
30
+ - MIT
31
+ metadata:
32
+ allowed_push_host: https://rubygems.org
33
+ homepage_uri: https://rubygems.org/gems/zarby
34
+ source_code_uri: https://rubygems.org/gems/zarby
35
+ changelog_uri: https://github.com/VianneySonneville/zarby/blob/main/CHANGELOG.md
36
+ github_repo: git@github.com:VianneySonneville/zarby.git
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 2.6.0
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubygems_version: 3.3.7
53
+ signing_key:
54
+ specification_version: 4
55
+ summary: String encoding and decoding with Ruby.
56
+ test_files: []