order_id 0.1.1 → 0.1.3

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
- SHA1:
3
- metadata.gz: 93485dc407c091c464d64fd1b5aed31ff1923b4d
4
- data.tar.gz: 568cb40c87ceeca4c6d120c958176dc2ddd6be4b
2
+ SHA256:
3
+ metadata.gz: 4411fb9039ddb6ce1173b1093eb5978ff8d0c04b12bdb51d3671448b2f16eba6
4
+ data.tar.gz: 517f9d854d8d469be93929b9fd778b8fd8765d39dfd9778bc271593aa37c5ef5
5
5
  SHA512:
6
- metadata.gz: 2699ecb2ad854be2f1ca734f0fa09c142dfa4001e74d0889dcf771a4ea3457420300711833238ab7eed967f801a0eecdd3e71c90eb5be5c7225e24ccca5735ea
7
- data.tar.gz: 9a850a1c2a4eba13dd762931ac52b8ba3baebe65dc8b6c5dd725b98bfc051965e09459ad8a1eadd9a17105d841aacb5968479b62c73e2ed9929e418e314c8760
6
+ metadata.gz: 6e8c88d48610a1eb1688d440fb22e02648ab8e55d5f8b07323653b01203db07989d32e65e95b7472116973492cea7b3d39b9cba718089049df3ebe6699ae06d2
7
+ data.tar.gz: 3c3ea8008b0bb8b03bfa8a7ef200bd887f7fffffcfae3cf06fd8ad8a1974c58064951c7c5a433d13ea11d93ccdebc873663b998238252c7c402646cfdcf18e77
data/.gitignore CHANGED
@@ -9,4 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
- /.idea/*
12
+ /.idea/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in json_data_extractor.gemspec
6
+ gemspec
data/README.md CHANGED
@@ -13,7 +13,7 @@ of XX chars separated by a custom separator-char.
13
13
  Add this line to your application's Gemfile:
14
14
 
15
15
  ```ruby
16
- gem 'OrderId'
16
+ gem 'order_id'
17
17
  ```
18
18
 
19
19
  And then execute:
@@ -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
- - `length`: number of decimal places in a timestamps. Makes no sense if it's over 20, common sense is 10 or 12.
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, length: 4) # 2022-08-21 20:49:34 +0000
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 "OrderId"
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
- # require "pry"
11
- # Pry.start
10
+ require "pry"
11
+ Pry.start
12
12
 
13
- require "irb"
14
- IRB.start(__FILE__)
@@ -0,0 +1,3 @@
1
+ module OrderId
2
+ VERSION = '0.1.3'
3
+ end
data/lib/order_id.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'order_id/version'
2
+ require 'bigdecimal'
3
+ module OrderId
4
+ DECIMAL_PLACES = 20
5
+ BASE = 36
6
+ SEPARATOR = '-'
7
+ GROUP_LENGTH = 5
8
+ ALLOWED_SEPARATORS = ['-', '_', '|', ':', '@', '.', '/', '#', '!', '$', '%', '^', '&', '*', '(', ')', '[', ']', '{', '}'].freeze
9
+
10
+ class FormatError < StandardError; end
11
+
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('.')
18
+ final = ts.to_i.to_s(base).upcase
19
+ final.scan(/.{1,#{group_length}}/).join(separator)
20
+ end
21
+
22
+ def self.get_time(id, decimal_places: DECIMAL_PLACES, base: BASE, separator: SEPARATOR)
23
+ id.delete!(separator)
24
+ ts = id.to_i(base) / BigDecimal("1e+#{decimal_places}")
25
+ Time.at(ts)
26
+ end
27
+ end
@@ -1,18 +1,18 @@
1
1
 
2
- lib = File.expand_path("../lib", __FILE__)
2
+ lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "OrderId/version"
4
+ require 'order_id/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "order_id"
7
+ spec.name = 'order_id'
8
8
  spec.version = OrderId::VERSION
9
- spec.authors = ["Max Buslaev"]
10
- spec.email = ["max@buslaev.net"]
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 = "https://github.com/austerlitz/order_id"
15
- spec.license = "MIT"
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 = "exe"
23
+ spec.bindir = 'exe'
24
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
- spec.require_paths = ["lib"]
25
+ spec.require_paths = ['lib']
26
26
 
27
- spec.add_development_dependency "bundler", "~> 1.17"
28
- spec.add_development_dependency "rake", "~> 10.0"
29
- spec.add_development_dependency "rspec", "~> 3.0"
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.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Buslaev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-21 00:00:00.000000000 Z
11
+ date: 2023-07-31 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: '1.17'
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: '1.17'
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,18 +89,18 @@ 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
- - OrderId.gemspec
84
97
  - README.md
85
98
  - Rakefile
86
99
  - bin/console
87
100
  - bin/setup
88
- - lib/OrderId.rb
89
- - lib/OrderId/version.rb
101
+ - lib/order_id.rb
102
+ - lib/order_id/version.rb
103
+ - order_id.gemspec
90
104
  homepage: https://github.com/austerlitz/order_id
91
105
  licenses:
92
106
  - MIT
@@ -106,8 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
120
  - !ruby/object:Gem::Version
107
121
  version: '0'
108
122
  requirements: []
109
- rubyforge_project:
110
- rubygems_version: 2.5.2
123
+ rubygems_version: 3.4.13
111
124
  signing_key:
112
125
  specification_version: 4
113
126
  summary: Timestamps-based ID strings.
data/.idea/workspace.xml DELETED
@@ -1,49 +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
- <option name="SHOW_DIALOG" value="false" />
6
- <option name="HIGHLIGHT_CONFLICTS" value="true" />
7
- <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
8
- <option name="LAST_RESOLUTION" value="IGNORE" />
9
- </component>
10
- <component name="Git.Settings">
11
- <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
12
- </component>
13
- <component name="MarkdownSettingsMigration">
14
- <option name="stateVersion" value="1" />
15
- </component>
16
- <component name="ProjectId" id="2DgD17KvwTjH9BGJd1Qsr1bJHzY" />
17
- <component name="ProjectLevelVcsManager" settingsEditedManually="true" />
18
- <component name="ProjectViewState">
19
- <option name="hideEmptyMiddlePackages" value="true" />
20
- <option name="showLibraryContents" value="true" />
21
- </component>
22
- <component name="PropertiesComponent">{
23
- &quot;keyToString&quot;: {
24
- &quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
25
- &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
26
- &quot;WebServerToolWindowFactoryState&quot;: &quot;false&quot;,
27
- &quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
28
- &quot;ruby.rails.projectView.checked&quot;: &quot;true&quot;,
29
- &quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
30
- }
31
- }</component>
32
- <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
33
- <component name="SpringUtil" SPRING_PRE_LOADER_OPTION="true" RAKE_SPRING_PRE_LOADER_OPTION="true" RAILS_SPRING_PRE_LOADER_OPTION="true" />
34
- <component name="TaskManager">
35
- <task active="true" id="Default" summary="Default task">
36
- <changelist id="4b873eb2-62f8-4b0c-a8f7-c2e6e71629fe" name="Changes" comment="" />
37
- <created>1661111615612</created>
38
- <option name="number" value="Default" />
39
- <option name="presentableId" value="Default" />
40
- <updated>1661111615612</updated>
41
- <workItem from="1661111617027" duration="4151000" />
42
- <workItem from="1661115973104" duration="395000" />
43
- </task>
44
- <servers />
45
- </component>
46
- <component name="TypeScriptGeneratedFilesManager">
47
- <option name="version" value="3" />
48
- </component>
49
- </project>
@@ -1,3 +0,0 @@
1
- module OrderId
2
- VERSION = "0.1.1"
3
- end
data/lib/OrderId.rb DELETED
@@ -1,26 +0,0 @@
1
- require "OrderId/version"
2
- require 'bigdecimal'
3
- module OrderId
4
- DECIMAL_LENGTH = 20
5
- BASE = 36
6
- SEPARATOR = '-'
7
- GROUP_LENGTH = 5
8
- class FormatError < StandardError; end
9
-
10
- def self.generate(length: DECIMAL_LENGTH, base: BASE, separator: SEPARATOR, group_length: GROUP_LENGTH)
11
- if separator =~ (/[\w\d]/)
12
- raise FormatError, "Characters not allowed as separator: `#{separator}`"
13
- end
14
- t = Time.now.to_f
15
- ts = "%.#{length}f" % t
16
- ts.delete!('.')
17
- final = ts.to_i.to_s(base).upcase
18
- final.scan(/.{1,#{group_length}}/).join(separator)
19
- end
20
-
21
- def self.get_time(id, length: DECIMAL_LENGTH, base: BASE, separator: SEPARATOR)
22
- id.delete!(separator)
23
- ts = id.to_i(base) / BigDecimal("1e+#{length}")
24
- Time.at(ts)
25
- end
26
- end