pseudo_random_value 1.0.2

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 46ff96cd08ec81519bc03d3c59327fc3cb4023f2e4dc477336e7253dbee2e34f
4
+ data.tar.gz: 1cae60a2de50cf2bb56a2095523f982598e679b5ae904a448c2825c550092566
5
+ SHA512:
6
+ metadata.gz: 5d66e773ece3c8355e8b0027912d522af52204c51c6436b314175c2784e2cf18eb0fc66a953dced369a440d7f6b15dc567e0625651829488671b7ba2469b4c74
7
+ data.tar.gz: cfa02b9a8d5f35cadbfc91d7e87a279448c82833c5796240107f3577352596e4675cd12a94ba62fa846b2f9a4442515fe42a9f8372656c2d3d64aeb69df9b90a
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ ruby '2.6.3'
4
+
5
+ gem 'rspec'
@@ -0,0 +1,49 @@
1
+ # PseudoRandomValue
2
+
3
+ Development for Ruby
4
+
5
+ # Description
6
+
7
+ PseudoRandomValue is a gem for creating token with a given length.
8
+ The length of the output token is determined by the number of arrays in the multidimensional array.
9
+
10
+ Incoming array example `arr_symbols = [['a', 1, 'C', 0 ],['H', 2, 's', 'D'],['V', 3, 4, 'p']]`
11
+
12
+ When using in a real app make sure to prepare "seed arrays" by running something like this:
13
+
14
+ `arr_symbols = []`
15
+
16
+ `7.times { arr_symbols << ((0..9).to_a | ('a'..'z').to_a | ('A'..'Z').to_a).shuffle }`
17
+
18
+ ### Install
19
+
20
+ ```
21
+ gem install pseudo_random_value
22
+ ```
23
+ or add `pseud_random_value` to your apps `Gemfile`
24
+
25
+ ```
26
+ gem 'pseudo_random_value'
27
+ ```
28
+
29
+ And then execute:
30
+
31
+ ```
32
+ bundle install
33
+ ```
34
+
35
+ ## Example
36
+
37
+ Open your favorite Terminal and run these commands.
38
+
39
+ `require 'pseudo_random_value'`
40
+
41
+ `prv = PseudoRandomValue.new(arr_symbols)`
42
+
43
+ `prv.new_value(token_counter)` replace `token_counter` with `1`
44
+
45
+ when you do, you will get something like this `aH3`
46
+
47
+ License
48
+ ----
49
+ MIT
@@ -0,0 +1,34 @@
1
+ class PseudoRandomValue
2
+ def initialize(arr_symbols)
3
+ if arr_symbols.first.is_a? Array
4
+ @arr_symbols = arr_symbols
5
+ else arr_symbols.first.is_a? String
6
+ @arr_symbols = arr_symbols.map {|s| s.split("") }
7
+ end
8
+
9
+ raise RuntimeError.new("Empty arr_symbols") if arr_symbols.empty?
10
+ end
11
+
12
+ def new_value(token_counter)
13
+ token_counter = 1 if token_counter == 0
14
+ output_value = output_value(@arr_symbols, token_counter).reverse
15
+ maximum_value = maximum_value(@arr_symbols)
16
+
17
+ message = "Sorry, number of characters is over"
18
+ raise RuntimeError.new(message) if token_counter >= maximum_value
19
+
20
+ output_value.join
21
+ end
22
+
23
+ private
24
+
25
+ def output_value(arr_symbols, token_counter)
26
+ arr_symbols.map.with_index do |symbols, i|
27
+ symbols[token_counter / (symbols.length ** i) % symbols.length]
28
+ end
29
+ end
30
+
31
+ def maximum_value(arr_symbols)
32
+ arr_symbols[0].length ** arr_symbols.size + 1
33
+ end
34
+ end
@@ -0,0 +1,14 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "pseudo_random_value"
5
+ s.version = "1.0.2"
6
+ s.date = "2020-05-29"
7
+ s.summary = "Pseudo-random value construction"
8
+ s.description = "Simple gem to create pseudo-random values"
9
+ s.author = "Dmitriy Smirnov"
10
+ s.email = "digens111@gmail.com"
11
+ s.files = `git ls-files`.split("\n")
12
+ s.homepage = "https://github.com/vergilsm/pseudo_random_value"
13
+ s.license = 'MIT'
14
+ end
@@ -0,0 +1,28 @@
1
+ require "rspec"
2
+ require_relative "../lib/pseudo_random_value"
3
+
4
+ RSpec.describe PseudoRandomValue do
5
+ describe "values" do
6
+ let(:arr_symbols) { [['a', 1, 'b', 9], ['g', 5, 7, 'k'], [0, 3, 'D', 'S']] }
7
+ let(:counter) { arr_symbols[0].length ** arr_symbols.size }
8
+ subject { PseudoRandomValue.new(arr_symbols.reverse) }
9
+
10
+ it "first_value" do
11
+ expect(subject.new_value(0)).to eq("#{arr_symbols[0][0]}" +
12
+ "#{arr_symbols[1][0]}" +
13
+ "#{arr_symbols[2][1]}")
14
+ end
15
+
16
+ it "next value" do
17
+ expect(subject.new_value(2)).to eq("#{arr_symbols[0][0]}" +
18
+ "#{arr_symbols[1][0]}" +
19
+ "#{arr_symbols[2][2]}")
20
+ end
21
+
22
+ it "last value" do
23
+ expect(subject.new_value(counter)).to eq("#{arr_symbols[0][0]}" +
24
+ "#{arr_symbols[1][0]}" +
25
+ "#{arr_symbols[2][0]}")
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,100 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
+ RSpec.configure do |config|
17
+ # rspec-expectations config goes here. You can use an alternate
18
+ # assertion/expectation library such as wrong or the stdlib/minitest
19
+ # assertions if you prefer.
20
+ config.expect_with :rspec do |expectations|
21
+ # This option will default to `true` in RSpec 4. It makes the `description`
22
+ # and `failure_message` of custom matchers include text for helper methods
23
+ # defined using `chain`, e.g.:
24
+ # be_bigger_than(2).and_smaller_than(4).description
25
+ # # => "be bigger than 2 and smaller than 4"
26
+ # ...rather than:
27
+ # # => "be bigger than 2"
28
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
29
+ end
30
+
31
+ # rspec-mocks config goes here. You can use an alternate test double
32
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
33
+ config.mock_with :rspec do |mocks|
34
+ # Prevents you from mocking or stubbing a method that does not exist on
35
+ # a real object. This is generally recommended, and will default to
36
+ # `true` in RSpec 4.
37
+ mocks.verify_partial_doubles = true
38
+ end
39
+
40
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
41
+ # have no way to turn it off -- the option exists only for backwards
42
+ # compatibility in RSpec 3). It causes shared context metadata to be
43
+ # inherited by the metadata hash of host groups and examples, rather than
44
+ # triggering implicit auto-inclusion in groups with matching metadata.
45
+ config.shared_context_metadata_behavior = :apply_to_host_groups
46
+
47
+ # The settings below are suggested to provide a good initial experience
48
+ # with RSpec, but feel free to customize to your heart's content.
49
+ =begin
50
+ # This allows you to limit a spec run to individual examples or groups
51
+ # you care about by tagging them with `:focus` metadata. When nothing
52
+ # is tagged with `:focus`, all examples get run. RSpec also provides
53
+ # aliases for `it`, `describe`, and `context` that include `:focus`
54
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
55
+ config.filter_run_when_matching :focus
56
+
57
+ # Allows RSpec to persist some state between runs in order to support
58
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
59
+ # you configure your source control system to ignore this file.
60
+ config.example_status_persistence_file_path = "spec/examples.txt"
61
+
62
+ # Limits the available syntax to the non-monkey patched syntax that is
63
+ # recommended. For more details, see:
64
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
65
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
66
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
67
+ config.disable_monkey_patching!
68
+
69
+ # This setting enables warnings. It's recommended, but in some cases may
70
+ # be too noisy due to issues in dependencies.
71
+ config.warnings = true
72
+
73
+ # Many RSpec users commonly either run the entire suite or an individual
74
+ # file, and it's useful to allow more verbose output when running an
75
+ # individual spec file.
76
+ if config.files_to_run.one?
77
+ # Use the documentation formatter for detailed output,
78
+ # unless a formatter has already been configured
79
+ # (e.g. via a command-line flag).
80
+ config.default_formatter = "doc"
81
+ end
82
+
83
+ # Print the 10 slowest examples and example groups at the
84
+ # end of the spec run, to help surface which specs are running
85
+ # particularly slow.
86
+ config.profile_examples = 10
87
+
88
+ # Run specs in random order to surface order dependencies. If you find an
89
+ # order dependency and want to debug it, you can fix the order by providing
90
+ # the seed, which is printed after each run.
91
+ # --seed 1234
92
+ config.order = :random
93
+
94
+ # Seed global randomization in this process using the `--seed` CLI option.
95
+ # Setting this allows you to use `--seed` to deterministically reproduce
96
+ # test failures related to randomization by passing the same `--seed` value
97
+ # as the one that triggered the failure.
98
+ Kernel.srand config.seed
99
+ =end
100
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pseudo_random_value
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Dmitriy Smirnov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-05-29 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Simple gem to create pseudo-random values
14
+ email: digens111@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - ".gitignore"
20
+ - ".rspec"
21
+ - Gemfile
22
+ - README.md
23
+ - lib/pseudo_random_value.rb
24
+ - pseudo_random_value.gemspec
25
+ - spec/pseudo_random_value_spec.rb
26
+ - spec/spec_helper.rb
27
+ homepage: https://github.com/vergilsm/pseudo_random_value
28
+ licenses:
29
+ - MIT
30
+ metadata: {}
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubygems_version: 3.0.3
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: Pseudo-random value construction
50
+ test_files: []