ot-rb 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ot/version.rb +1 -1
- data/lib/ot/wrapped_operation.rb +74 -0
- data/lib/ot.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3332d709ee8816de320fecaee78f9a7e1af9060cad7189cf812b61e986199ff2
|
4
|
+
data.tar.gz: 6c9de6bcf7fbda98a0337c7e7770f66b008a747d7aaa7a601715724c3fa70903
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 200e2aadcf4c1ddac3fabb28e405eca3a66b1d8c550a2199d486902d9e5112b6df353040ba331cb215b082c40b229be71ba146a5502871b5d83ebae4bab2b19e
|
7
|
+
data.tar.gz: b20553885d5c125ccb6750b46f3e4886a1dab6a49cb0279589761557d5f430dfbfadb968792948648f5daeeb4b1ef00d0a8990d0cb487045eeceec32baf7fa04
|
data/lib/ot/version.rb
CHANGED
@@ -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
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.
|
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
|
+
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: []
|