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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4411fb9039ddb6ce1173b1093eb5978ff8d0c04b12bdb51d3671448b2f16eba6
4
- data.tar.gz: 517f9d854d8d469be93929b9fd778b8fd8765d39dfd9778bc271593aa37c5ef5
3
+ metadata.gz: 1dc89e82dbea7bdde42f744901b35f280460e00b55240d39a3dae4235f3323ed
4
+ data.tar.gz: e34ab501224055ade294cac2883ef16d01e7c2930bf74c778cf5267581647545
5
5
  SHA512:
6
- metadata.gz: 6e8c88d48610a1eb1688d440fb22e02648ab8e55d5f8b07323653b01203db07989d32e65e95b7472116973492cea7b3d39b9cba718089049df3ebe6699ae06d2
7
- data.tar.gz: 3c3ea8008b0bb8b03bfa8a7ef200bd887f7fffffcfae3cf06fd8ad8a1974c58064951c7c5a433d13ea11d93ccdebc873663b998238252c7c402646cfdcf18e77
6
+ metadata.gz: c463baa1bc5d498e5f057797f23c4dd8191cbe220a29b24f752f66fab484e1d68a7382fec31096bef9d4c2cc42d2cd3e196297a24c439c19c0266541d4d2e0db
7
+ data.tar.gz: 1e537ab3dda497c4b60fbedb2e4fd273df9f3b081a5a1eab21d0aacced2379489b3f3c9fa3d72cc1a9abd3cad260aa23e27108f019cffee381065432a6158ee4
@@ -1,3 +1,3 @@
1
1
  module OrderId
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
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 = 20
5
- BASE = 36
6
- SEPARATOR = '-'
7
- GROUP_LENGTH = 5
8
- ALLOWED_SEPARATORS = ['-', '_', '|', ':', '@', '.', '/', '#', '!', '$', '%', '^', '&', '*', '(', ')', '[', ']', '{', '}'].freeze
4
+ DECIMAL_PLACES = 20
5
+ BASE = 36
6
+ SEPARATOR = '-'
7
+ GROUP_LENGTH = 5
9
8
 
10
- class FormatError < StandardError; end
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
- def self.generate(decimal_places: DECIMAL_PLACES, base: BASE, separator: SEPARATOR, group_length: GROUP_LENGTH)
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.3
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-07-31 00:00:00.000000000 Z
11
+ date: 2023-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler