order_id 0.1.2 → 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
2
  SHA256:
3
- metadata.gz: db6b222582403d19512937c93e57b3071a412fb2748069a80ba6fc4af5c8351a
4
- data.tar.gz: 4a5b97c50fa99a60f5ed205377d54120e7945ba32927fc8d51425c2a46cf7f53
3
+ metadata.gz: 4411fb9039ddb6ce1173b1093eb5978ff8d0c04b12bdb51d3671448b2f16eba6
4
+ data.tar.gz: 517f9d854d8d469be93929b9fd778b8fd8765d39dfd9778bc271593aa37c5ef5
5
5
  SHA512:
6
- metadata.gz: 13ec68fd3c728970b339b9915ec3bab1bc3b2542dc3e631d5b469438c40508d3dd097309b48c242bc39d6fb59ba8b0b5e9b89765f64db876108a8b683fe729c3
7
- data.tar.gz: d67f31250fe0c83fc4b3aa44e9c84f288ca781dbb6d6aad551e54787d91a02796bf1378a42c3709fa865bd93cde5d98deeb7c79febf6308104363ca604b77bc4
6
+ metadata.gz: 6e8c88d48610a1eb1688d440fb22e02648ab8e55d5f8b07323653b01203db07989d32e65e95b7472116973492cea7b3d39b9cba718089049df3ebe6699ae06d2
7
+ data.tar.gz: 3c3ea8008b0bb8b03bfa8a7ef200bd887f7fffffcfae3cf06fd8ad8a1974c58064951c7c5a433d13ea11d93ccdebc873663b998238252c7c402646cfdcf18e77
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
@@ -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__)
@@ -1,3 +1,3 @@
1
1
  module OrderId
2
- VERSION = "0.1.2"
2
+ VERSION = '0.1.3'
3
3
  end
data/lib/order_id.rb CHANGED
@@ -1,26 +1,27 @@
1
- require "order_id/version"
1
+ require 'order_id/version'
2
2
  require 'bigdecimal'
3
3
  module OrderId
4
- DECIMAL_LENGTH = 20
4
+ DECIMAL_PLACES = 20
5
5
  BASE = 36
6
6
  SEPARATOR = '-'
7
7
  GROUP_LENGTH = 5
8
+ ALLOWED_SEPARATORS = ['-', '_', '|', ':', '@', '.', '/', '#', '!', '$', '%', '^', '&', '*', '(', ')', '[', ']', '{', '}'].freeze
9
+
8
10
  class FormatError < StandardError; end
9
11
 
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!('.')
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('.')
17
18
  final = ts.to_i.to_s(base).upcase
18
19
  final.scan(/.{1,#{group_length}}/).join(separator)
19
20
  end
20
21
 
21
- def self.get_time(id, length: DECIMAL_LENGTH, base: BASE, separator: SEPARATOR)
22
+ def self.get_time(id, decimal_places: DECIMAL_PLACES, base: BASE, separator: SEPARATOR)
22
23
  id.delete!(separator)
23
- ts = id.to_i(base) / BigDecimal("1e+#{length}")
24
+ ts = id.to_i(base) / BigDecimal("1e+#{decimal_places}")
24
25
  Time.at(ts)
25
26
  end
26
27
  end
data/order_id.gemspec CHANGED
@@ -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 "order_id/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.2
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-10-08 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,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.2.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>