ot-rb 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: ff6ebc3c63eb7cddc35d2a2e974d08e27328e88615a23c3c102f4165a1ea1a80
4
- data.tar.gz: ffd46651184fe4c2d3c6e1894900965a17ac896bdd0a591caca93f3592dcfccd
3
+ metadata.gz: 3332d709ee8816de320fecaee78f9a7e1af9060cad7189cf812b61e986199ff2
4
+ data.tar.gz: 6c9de6bcf7fbda98a0337c7e7770f66b008a747d7aaa7a601715724c3fa70903
5
5
  SHA512:
6
- metadata.gz: f696afed273698e5a949149bb75b30dc547469cda8e4f6339346ec6168c80eee01b78c3778ace6b1756980b17f328635ef17d267c9b4b0acd5d5ace13ea6c1e5
7
- data.tar.gz: 12e643d93c95accba36293795c8461499c97f4ab62474b750a2031929ec2717d295f19dfa5b1c792af576ecd695eb41804329ba18aed35841422b040caa682d4
6
+ metadata.gz: 200e2aadcf4c1ddac3fabb28e405eca3a66b1d8c550a2199d486902d9e5112b6df353040ba331cb215b082c40b229be71ba146a5502871b5d83ebae4bab2b19e
7
+ data.tar.gz: b20553885d5c125ccb6750b46f3e4886a1dab6a49cb0279589761557d5f430dfbfadb968792948648f5daeeb4b1ef00d0a8990d0cb487045eeceec32baf7fa04
data/lib/ot/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OT
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This is a port of ot.js to Ruby.
4
+ # https://github.com/Operational-Transformation/ot.js/blob/v0.0.15/lib/wrapped-operation.js
5
+
6
+ # Copyright (c) 2012-2014 Tim Baumann, http://timbaumann.info
7
+ # Released under the MIT license
8
+ # https://opensource.org/licenses/mit-license.php
9
+
10
+ module OT
11
+ class WrappedOperation
12
+ # @return [TextOperation, WrappedOperation]
13
+ attr_reader :wrapped
14
+
15
+ # @return [Object]
16
+ attr_reader :meta
17
+
18
+ # @param operation [TextOperation, WrappedOperation]
19
+ # @param meta [Object]
20
+ def initialize(operation, meta)
21
+ @wrapped = operation
22
+ @meta = meta
23
+ end
24
+
25
+ def apply(...)
26
+ wrapped.apply(...)
27
+ end
28
+
29
+ # @param other [WrappedOperation]
30
+ def compose(other)
31
+ WrappedOperation.new(
32
+ wrapped.compose(other.wrapped),
33
+ self.class.compose_meta(meta, other.meta),
34
+ )
35
+ end
36
+
37
+ class << self
38
+ # @param wop1 [WrappedOperation]
39
+ # @param wop2 [WrappedOperation]
40
+ # @return [(WrappedOperation, WrappedOperation)]
41
+ def transform(wop1, wop2)
42
+ op1_t, op2_t = wop1.wrapped.class.transform(wop1.wrapped, wop2.wrapped)
43
+
44
+ [
45
+ WrappedOperation.new(op1_t, transform_meta(wop1.meta, wop2)),
46
+ WrappedOperation.new(op2_t, transform_meta(wop2.meta, wop1)),
47
+ ]
48
+ end
49
+
50
+ # @param meta [Object]
51
+ # @param operation [WrappedOperation]
52
+ # @return [Object]
53
+ def transform_meta(meta, wop)
54
+ if meta.respond_to?(:transform)
55
+ meta.transform(wop)
56
+ else
57
+ meta
58
+ end
59
+ end
60
+
61
+ # @param meta1 [#compose, #merge, Object]
62
+ # @param meta2 [#compose, #merge, Object]
63
+ def compose_meta(meta1, meta2)
64
+ if meta1.respond_to?(:compose)
65
+ meta1.compose(meta2)
66
+ elsif meta1.respond_to?(:merge)
67
+ meta1.merge(meta2)
68
+ else
69
+ meta2
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
data/lib/ot.rb CHANGED
@@ -5,3 +5,4 @@ end
5
5
 
6
6
  require_relative "ot/version"
7
7
  require_relative "ot/text_operation"
8
+ require_relative "ot/wrapped_operation"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ot-rb
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
  - Tomoya Chiba
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-11 00:00:00.000000000 Z
11
+ date: 2023-07-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: The ruby port of ot.js
14
14
  email:
@@ -31,6 +31,7 @@ files:
31
31
  - lib/ot/text_operation/build_dsl.rb
32
32
  - lib/ot/text_operation/iterator.rb
33
33
  - lib/ot/version.rb
34
+ - lib/ot/wrapped_operation.rb
34
35
  - sig/ot/rb.rbs
35
36
  homepage: https://github.com/tomoasleep/ot-rb
36
37
  licenses: []