order_id 0.1.2 → 0.1.4
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 +4 -4
- data/Gemfile +6 -0
- data/README.md +2 -2
- data/bin/console +3 -5
- data/lib/order_id/version.rb +1 -1
- data/lib/order_id.rb +15 -15
- data/order_id.gemspec +13 -12
- metadata +22 -8
- data/.idea/workspace.xml +0 -57
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/Gemfile
ADDED
data/README.md
CHANGED
@@ -32,7 +32,7 @@ OrderId.get_time('G3RRY-ZMIHR-CCZ3P-FGXM') # 2022-08-21 20:33:18 +0000
|
|
32
32
|
```
|
33
33
|
### Parameters
|
34
34
|
OrderId takes four optional parameters:
|
35
|
-
- `
|
35
|
+
- `decimal_places`: number of decimal places in a timestamp. Makes no sense if it's over 20, common sense is 10 or 12.
|
36
36
|
- `base`: base number system. Defaults to 36, but any arbitrary base is a good place to obfuscate your ids. E.g . `OrderId.generate(base: 12) # 12616-51312-6751B-A87B1-72235-444`
|
37
37
|
- `separator`: a separator char. Defaults to `-` but can be `'/'` or any non-digit and non-word character
|
38
38
|
- `group_length`: a number of chars in groups separated by a `separator`. Defaults to 4. `OrderId.generate(base: 12, length: 4, group_length: 8) # "1A434285-32526"`
|
@@ -41,7 +41,7 @@ OrderId takes four optional parameters:
|
|
41
41
|
If you know the parameters which the Id has been generated with you can restore a timestamp the Id was based on.
|
42
42
|
|
43
43
|
```ruby
|
44
|
-
OrderId.get_time('1A434285-32526', base: 12,
|
44
|
+
OrderId.get_time('1A434285-32526', base: 12, decimal_places: 4) # 2022-08-21 20:49:34 +0000
|
45
45
|
```
|
46
46
|
|
47
47
|
## Development
|
data/bin/console
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require "bundler/setup"
|
4
|
-
require "
|
4
|
+
require "order_id"
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
8
|
|
9
9
|
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
|
11
|
-
|
10
|
+
require "pry"
|
11
|
+
Pry.start
|
12
12
|
|
13
|
-
require "irb"
|
14
|
-
IRB.start(__FILE__)
|
data/lib/order_id/version.rb
CHANGED
data/lib/order_id.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
|
-
require
|
1
|
+
require 'order_id/version'
|
2
2
|
require 'bigdecimal'
|
3
3
|
module OrderId
|
4
|
-
|
5
|
-
BASE
|
6
|
-
SEPARATOR
|
7
|
-
GROUP_LENGTH
|
8
|
-
class FormatError < StandardError; end
|
4
|
+
DECIMAL_PLACES = 20
|
5
|
+
BASE = 36
|
6
|
+
SEPARATOR = '-'
|
7
|
+
GROUP_LENGTH = 5
|
9
8
|
|
10
|
-
def self.generate(
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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)
|
15
|
+
|
16
|
+
ts = format("%.#{decimal_places}f", timestamp).delete('.')
|
17
17
|
final = ts.to_i.to_s(base).upcase
|
18
18
|
final.scan(/.{1,#{group_length}}/).join(separator)
|
19
19
|
end
|
20
20
|
|
21
|
-
def self.get_time(id,
|
21
|
+
def self.get_time(id, decimal_places: DECIMAL_PLACES, base: BASE, separator: SEPARATOR)
|
22
22
|
id.delete!(separator)
|
23
|
-
ts = id.to_i(base) / BigDecimal("1e+#{
|
23
|
+
ts = id.to_i(base) / BigDecimal("1e+#{decimal_places}")
|
24
24
|
Time.at(ts)
|
25
25
|
end
|
26
26
|
end
|
data/order_id.gemspec
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require 'order_id/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'order_id'
|
8
8
|
spec.version = OrderId::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Max Buslaev']
|
10
|
+
spec.email = ['max@buslaev.net']
|
11
11
|
|
12
12
|
spec.summary = %q{Timestamps-based ID strings.}
|
13
13
|
spec.description = %q{Generates an ID string best used for orders/invoices/etc. Timestamp-based, reverse parseable.}
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
14
|
+
spec.homepage = 'https://github.com/austerlitz/order_id'
|
15
|
+
spec.license = 'MIT'
|
16
16
|
|
17
17
|
|
18
18
|
# Specify which files should be added to the gem when it is released.
|
@@ -20,13 +20,14 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
21
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
22
|
end
|
23
|
-
spec.bindir =
|
23
|
+
spec.bindir = 'exe'
|
24
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
-
spec.require_paths = [
|
25
|
+
spec.require_paths = ['lib']
|
26
26
|
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
27
|
+
spec.add_development_dependency 'bundler'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
30
|
+
spec.add_development_dependency 'pry'
|
30
31
|
|
31
32
|
spec.add_dependency 'bigdecimal'
|
32
33
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
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:
|
11
|
+
date: 2023-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
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: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: bigdecimal
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -75,10 +89,10 @@ extensions: []
|
|
75
89
|
extra_rdoc_files: []
|
76
90
|
files:
|
77
91
|
- ".gitignore"
|
78
|
-
- ".idea/workspace.xml"
|
79
92
|
- ".rspec"
|
80
93
|
- ".travis.yml"
|
81
94
|
- CODE_OF_CONDUCT.md
|
95
|
+
- Gemfile
|
82
96
|
- LICENSE.txt
|
83
97
|
- README.md
|
84
98
|
- Rakefile
|
@@ -106,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
120
|
- !ruby/object:Gem::Version
|
107
121
|
version: '0'
|
108
122
|
requirements: []
|
109
|
-
rubygems_version: 3.
|
123
|
+
rubygems_version: 3.4.13
|
110
124
|
signing_key:
|
111
125
|
specification_version: 4
|
112
126
|
summary: Timestamps-based ID strings.
|
data/.idea/workspace.xml
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<project version="4">
|
3
|
-
<component name="ChangeListManager">
|
4
|
-
<list default="true" id="4b873eb2-62f8-4b0c-a8f7-c2e6e71629fe" name="Changes" comment="">
|
5
|
-
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
|
6
|
-
<change beforePath="$PROJECT_DIR$/OrderId.gemspec" beforeDir="false" afterPath="$PROJECT_DIR$/order_id.gemspec" afterDir="false" />
|
7
|
-
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
|
8
|
-
<change beforePath="$PROJECT_DIR$/lib/OrderId.rb" beforeDir="false" afterPath="$PROJECT_DIR$/lib/order_id.rb" afterDir="false" />
|
9
|
-
<change beforePath="$PROJECT_DIR$/lib/OrderId/version.rb" beforeDir="false" afterPath="$PROJECT_DIR$/lib/order_id/version.rb" afterDir="false" />
|
10
|
-
<change beforePath="$PROJECT_DIR$/spec/OrderId_spec.rb" beforeDir="false" afterPath="$PROJECT_DIR$/spec/order_id_spec.rb" afterDir="false" />
|
11
|
-
</list>
|
12
|
-
<option name="SHOW_DIALOG" value="false" />
|
13
|
-
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
14
|
-
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
15
|
-
<option name="LAST_RESOLUTION" value="IGNORE" />
|
16
|
-
</component>
|
17
|
-
<component name="Git.Settings">
|
18
|
-
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
19
|
-
</component>
|
20
|
-
<component name="MarkdownSettingsMigration">
|
21
|
-
<option name="stateVersion" value="1" />
|
22
|
-
</component>
|
23
|
-
<component name="ProjectId" id="2DgD17KvwTjH9BGJd1Qsr1bJHzY" />
|
24
|
-
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
|
25
|
-
<component name="ProjectViewState">
|
26
|
-
<option name="hideEmptyMiddlePackages" value="true" />
|
27
|
-
<option name="showLibraryContents" value="true" />
|
28
|
-
</component>
|
29
|
-
<component name="PropertiesComponent"><![CDATA[{
|
30
|
-
"keyToString": {
|
31
|
-
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
32
|
-
"RunOnceActivity.ShowReadmeOnStart": "true",
|
33
|
-
"WebServerToolWindowFactoryState": "false",
|
34
|
-
"last_opened_file_path": "/var/www/order_id",
|
35
|
-
"nodejs_package_manager_path": "npm",
|
36
|
-
"ruby.rails.projectView.checked": "true",
|
37
|
-
"vue.rearranger.settings.migration": "true"
|
38
|
-
}
|
39
|
-
}]]></component>
|
40
|
-
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
41
|
-
<component name="SpringUtil" SPRING_PRE_LOADER_OPTION="true" RAKE_SPRING_PRE_LOADER_OPTION="true" RAILS_SPRING_PRE_LOADER_OPTION="true" />
|
42
|
-
<component name="TaskManager">
|
43
|
-
<task active="true" id="Default" summary="Default task">
|
44
|
-
<changelist id="4b873eb2-62f8-4b0c-a8f7-c2e6e71629fe" name="Changes" comment="" />
|
45
|
-
<created>1661111615612</created>
|
46
|
-
<option name="number" value="Default" />
|
47
|
-
<option name="presentableId" value="Default" />
|
48
|
-
<updated>1661111615612</updated>
|
49
|
-
<workItem from="1661111617027" duration="4151000" />
|
50
|
-
<workItem from="1665209439789" duration="393000" />
|
51
|
-
</task>
|
52
|
-
<servers />
|
53
|
-
</component>
|
54
|
-
<component name="TypeScriptGeneratedFilesManager">
|
55
|
-
<option name="version" value="3" />
|
56
|
-
</component>
|
57
|
-
</project>
|