order_id 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/order_id/version.rb +1 -1
- data/lib/order_id.rb +11 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1dc89e82dbea7bdde42f744901b35f280460e00b55240d39a3dae4235f3323ed
|
4
|
+
data.tar.gz: e34ab501224055ade294cac2883ef16d01e7c2930bf74c778cf5267581647545
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c463baa1bc5d498e5f057797f23c4dd8191cbe220a29b24f752f66fab484e1d68a7382fec31096bef9d4c2cc42d2cd3e196297a24c439c19c0266541d4d2e0db
|
7
|
+
data.tar.gz: 1e537ab3dda497c4b60fbedb2e4fd273df9f3b081a5a1eab21d0aacced2379489b3f3c9fa3d72cc1a9abd3cad260aa23e27108f019cffee381065432a6158ee4
|
data/lib/order_id/version.rb
CHANGED
data/lib/order_id.rb
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
require 'order_id/version'
|
2
2
|
require 'bigdecimal'
|
3
3
|
module OrderId
|
4
|
-
DECIMAL_PLACES
|
5
|
-
BASE
|
6
|
-
SEPARATOR
|
7
|
-
GROUP_LENGTH
|
8
|
-
ALLOWED_SEPARATORS = ['-', '_', '|', ':', '@', '.', '/', '#', '!', '$', '%', '^', '&', '*', '(', ')', '[', ']', '{', '}'].freeze
|
4
|
+
DECIMAL_PLACES = 20
|
5
|
+
BASE = 36
|
6
|
+
SEPARATOR = '-'
|
7
|
+
GROUP_LENGTH = 5
|
9
8
|
|
10
|
-
|
9
|
+
def self.generate(decimal_places: DECIMAL_PLACES, base: BASE, separator: SEPARATOR, group_length: GROUP_LENGTH, timestamp: Time.now.to_f)
|
10
|
+
raise ArgumentError, "Invalid separator: '#{separator}'. Separator should be a non-alphanumeric character." unless separator =~ /[^a-zA-Z0-9]/
|
11
|
+
raise ArgumentError, "Invalid decimal places: '#{decimal_places}'. Decimal places should be a positive integer." unless decimal_places.is_a?(Integer) && decimal_places.positive?
|
12
|
+
raise ArgumentError, "Invalid base: '#{base}'. Base should be an integer between 2 and 36." unless base.is_a?(Integer) && base.between?(2, 36)
|
13
|
+
raise ArgumentError, "Invalid group length: '#{group_length}'. Group length should be a positive integer." unless group_length.is_a?(Integer) && group_length.positive?
|
14
|
+
raise ArgumentError, "Invalid timestamp: '#{timestamp}'. Timestamp should be a floating point number." unless timestamp.is_a?(Float)
|
11
15
|
|
12
|
-
|
13
|
-
raise FormatError, "Characters not allowed as separator: '#{separator}'" unless ALLOWED_SEPARATORS.include?(separator)
|
14
|
-
raise FormatError, 'Length should be positive' unless decimal_places.positive?
|
15
|
-
|
16
|
-
t = Time.now.to_f
|
17
|
-
ts = format("%.#{decimal_places}f", t).delete('.')
|
16
|
+
ts = format("%.#{decimal_places}f", timestamp).delete('.')
|
18
17
|
final = ts.to_i.to_s(base).upcase
|
19
18
|
final.scan(/.{1,#{group_length}}/).join(separator)
|
20
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: order_id
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Buslaev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|