fractional_indexer 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb26a758da0bb2de8108cd4a77fc48779488abaa647e908a02bb3d8476a29b5e
4
- data.tar.gz: 1ea8bf3b0c21a1d70daba1843bc15ff6a50943b1b1510a91631260c37ff53def
3
+ metadata.gz: 529455a944319ae06942cb577687a1c6d06e2869316d0f715c7a03415704c0a9
4
+ data.tar.gz: afccd5d154f1637648c6418637d4243a518c0774f575a4b2eea909db0f89e762
5
5
  SHA512:
6
- metadata.gz: dffb6fcbf7e72af343944c33d35cd287a0e7fb7310b42064b6e567de50f6cbf551a5f05132102484080f6ce0062a762effd1b5eac6bc177c26f838ab6c35bfbc
7
- data.tar.gz: d0316fe102d0e6259a76f699affc2016c1b6ac891d8e22740ef3c0b316124490475c406632f6bcbd75f21715da13e0991a0589ca57d76b023094823d28378b68
6
+ metadata.gz: ab6facf8bbf718cdc36fd3bfb74d27913b3f68635b1a573e72426ee70a1d132b860f0008cef13d6bca89273f24ca226c765e4a44f80591e5da058e8e9fe71518
7
+ data.tar.gz: 933bf9eca9dfd21b40ba7fda2bb4951cf198fd398580e800118366fd5b58e4514b5744739ecb5192ef4b5dbea4b1a5994f692de79e7ed329a5875512f8f9d4be
data/README.md CHANGED
@@ -1,10 +1,15 @@
1
- # FractionalIndexer
1
+ # Fractional Indexer
2
2
 
3
3
  [![codecov](https://codecov.io/gh/kazu-2020/fractional_indexer/graph/badge.svg?token=OCCYE4EKT1)](https://codecov.io/gh/kazu-2020/fractional_indexer)
4
+ [![test](https://github.com/kazu-2020/fractional_indexer/actions/workflows/ruby.yml/badge.svg?branch=main&event=push)](https://github.com/kazu-2020/fractional_indexer/actions/workflows/ruby.yml)
4
5
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/fractional_indexer`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+ > efficient data insertion and sorting through fractional indexing
6
7
 
7
- TODO: Delete this and the text above, and describe your gem
8
+ This gem is designed to achieve "[Realtime editing of ordered sequences](https://www.figma.com/blog/realtime-editing-of-ordered-sequences/#fractional-indexing)" as featured in a Figma blog post.
9
+
10
+ Specifically, it implements Fractional Indexing as a means of managing order, realized through strings. By managing indexes as strings, it significantly delays the occurrence of index duplication that can arise when implementing Fractional Indexing with floating-point numbers. Additionally, using strings allows for the representation of a much larger range of numbers in a single digit compared to decimal numbers (by default, a single digit is represented in base-62).
11
+
12
+ This gem was implemented based on the excellent article "[Implementing Fractional Indexing.](https://observablehq.com/@dgreensp/implementing-fractional-indexing)" I would like to express my gratitude to David Greenspan, the author of the article.
8
13
 
9
14
  ## Installation
10
15
 
@@ -24,17 +29,71 @@ Or install it yourself as:
24
29
 
25
30
  ## Usage
26
31
 
27
- TODO: Write usage instructions here
32
+ ### Generate Order key
33
+
34
+ To generate an order key, use the `FractionalIndexer.generate_key` method. This method can take two arguments: prev_key and next_key, both of which can be either nil or a string (excluding empty strings).
35
+
36
+ The characters that can be used in the strings are available for review in `FractionalIndexer.configuration.digits`.
37
+
38
+ ```ruby
39
+ require 'fractional_indexer'
40
+
41
+ # create first order key
42
+ FractionalIndexer.generate_key
43
+ # => "a0"
44
+
45
+ # increment
46
+ FractionalIndexer.generate_key(prev_key: 'a0')
47
+ # => "a1"
28
48
 
29
- ## Development
49
+ # decrement
50
+ FractionalIndexer.generate_key(next_key: 'a0')
51
+ # => "Zz"
30
52
 
31
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
53
+ # between prev_key and next_key
54
+ FractionalIndexer.generate_key(prev_key: 'a0', next_key: 'a2')
55
+ # => "a1"
32
56
 
33
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
57
+ # prev_key should be less than next_key
58
+ FractionalIndexer.generate_key(prev_key: 'a2', next_key: 'a1')
59
+ # => error
60
+ FractionalIndexer.generate_key(prev_key: 'a1', next_key: 'a1')
61
+ # => error
62
+ ```
63
+
64
+ ## Configure
65
+
66
+ ### base
67
+
68
+ You can set the base (number system) used to represent each digit. The possible values are :base_10, :base_62, and :base_94. (The default is :base_62.)
69
+
70
+ Note: base_10 is primarily intended for operational verification and debugging purposes.
71
+
72
+ ```ruby
73
+ require 'fractional_indexer'
74
+
75
+ FractionalIndexer.configure do |config|
76
+ config.base = :base_10
77
+ end
78
+ FractionalIndexer.configuration.digits.join
79
+ # => "0123456789"
80
+
81
+ FractionalIndexer.configure do |config|
82
+ config.base = :base_62
83
+ end
84
+ FractionalIndexer.configuration.digits.join
85
+ # => "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
86
+
87
+ FractionalIndexer.configure do |config|
88
+ config.base = :base_94
89
+ end
90
+ FractionalIndexer.configuration.digits.join
91
+ # => "!\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
92
+ ```
34
93
 
35
94
  ## Contributing
36
95
 
37
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fractional_indexer.
96
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kazu-2020/fractional_indexer.
38
97
 
39
98
  ## License
40
99
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FractionalIndexer
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fractional_indexer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kazu