y-rb 0.4.5-x86_64-darwin → 0.5.0-x86_64-darwin

Sign up to get free protection for your applications and to get access to all the features.
data/lib/y/map.rb CHANGED
@@ -70,7 +70,7 @@ module Y
70
70
  # m.delete(:nosuch) { |key| "Key #{key} not found" }# => "Key nosuch not found"
71
71
  # m # => {}
72
72
  #
73
- # @param key [String|Symbol]
73
+ # @param key [String, Symbol]
74
74
  # @return [void]
75
75
  def delete(key)
76
76
  value = document.current_transaction { |tx| ymap_remove(tx, key) }
@@ -96,7 +96,7 @@ module Y
96
96
  document.current_transaction { |tx| ymap_each(tx, block) }
97
97
  end
98
98
 
99
- # @return [true|false]
99
+ # @return [true, false]
100
100
  def key?(key)
101
101
  document.current_transaction { |tx| ymap_contains(tx, key) }
102
102
  end
@@ -143,7 +143,7 @@ module Y
143
143
  # Check if a certain key is in the Map
144
144
  #
145
145
  # @param tx [Y::Transaction]
146
- # @param key [String|Symbol]
146
+ # @param key [String, Symbol]
147
147
  # @return [Boolean] True, if and only if the key exists
148
148
 
149
149
  # @!method ymap_each(tx, proc)
@@ -151,21 +151,21 @@ module Y
151
151
  # with the key and the value as arguments.
152
152
  #
153
153
  # @param tx [Y::Transaction]
154
- # @param proc [Proc<String|Any>] A proc that is called for every element
154
+ # @param proc [Proc<String, Any>] A proc that is called for every element
155
155
 
156
156
  # @!method ymap_get(tx, key)
157
157
  # Returns stored value for key or nil if none is present
158
158
  #
159
159
  # @param tx [Y::Transaction]
160
- # @param key [String|Symbol]
161
- # @return [Object|nil] Value or nil
160
+ # @param key [String, Symbol]
161
+ # @return [Object, nil] Value or nil
162
162
 
163
163
  # @!method ymap_insert(tx, key, value)
164
164
  # Insert value for key. In case the key already exists, the previous value
165
165
  # will be overwritten.
166
166
  #
167
167
  # @param tx [Y::Transaction]
168
- # @param key [String|Symbol]
168
+ # @param key [String, Symbol]
169
169
  # @param value [Object]
170
170
 
171
171
  # @!method ymap_observe(callback)
@@ -177,7 +177,7 @@ module Y
177
177
  # Removes key-value pair from Map if key exists.
178
178
  #
179
179
  # @param tx [Y::Transaction]
180
- # @param key [String|Symbol]
180
+ # @param key [String, Symbol]
181
181
 
182
182
  # @!method ymap_size(tx)
183
183
  # Returns number of key-value pairs stored in map
data/lib/y/text.rb CHANGED
@@ -116,8 +116,8 @@ module Y
116
116
  # - Hash (where the the types of key and values must be supported)
117
117
  #
118
118
  # @param index [Integer]
119
- # @param value [String|Numeric|Array|Hash]
120
- # @param attrs [Hash|nil]
119
+ # @param value [String, Numeric, Array, Hash]
120
+ # @param attrs [Hash, nil]
121
121
  # @return [void]
122
122
  def insert(index, value, attrs = nil)
123
123
  document.current_transaction do |tx|
@@ -225,7 +225,7 @@ module Y
225
225
  # @return [void]
226
226
  def slice!(*args)
227
227
  document.current_transaction do |tx|
228
- if args.size.zero?
228
+ if args.empty?
229
229
  raise ArgumentError,
230
230
  "Provide one of `index`, `range`, `start, length` as arguments"
231
231
  end
data/lib/y/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Y
4
- VERSION = "0.4.5"
4
+ VERSION = "0.5.0"
5
5
  end
data/lib/y/xml.rb CHANGED
@@ -31,7 +31,7 @@ module Y
31
31
  # Retrieve node at index
32
32
  #
33
33
  # @param index [Integer]
34
- # @return [Y::XMLElement|nil]
34
+ # @return [Y::XMLElement, nil]
35
35
  def [](index)
36
36
  node = document.current_transaction { |tx| yxml_element_get(tx, index) }
37
37
  node&.document = document
@@ -76,7 +76,7 @@ module Y
76
76
  # Optional input is pushed to the text if provided
77
77
  #
78
78
  # @param index [Integer]
79
- # @param input [String|nil]
79
+ # @param input [String, nil]
80
80
  # @return [Y::XMLText]
81
81
  def insert_text(index, input = "")
82
82
  text = document.current_transaction do |tx|
@@ -88,7 +88,7 @@ module Y
88
88
 
89
89
  # Retrieve element or text adjacent (next) to this element
90
90
  #
91
- # @return [Y::XMLElement|Y::XMLText|nil]
91
+ # @return [Y::XMLElement, Y::XMLText, nil]
92
92
  def next_sibling
93
93
  node = document.current_transaction { |tx| yxml_element_next_sibling(tx) }
94
94
  node&.document = document
@@ -120,7 +120,7 @@ module Y
120
120
 
121
121
  # Retrieve parent element
122
122
  #
123
- # @return [Y::XMLElement|nil]
123
+ # @return [Y::XMLElement, nil]
124
124
  def parent
125
125
  node = yxml_element_parent
126
126
  node.document = document
@@ -129,7 +129,7 @@ module Y
129
129
 
130
130
  # Retrieve element or text adjacent (previous) to this element
131
131
  #
132
- # @return [Y::XMLElement|Y::XMLText|nil]
132
+ # @return [Y::XMLElement, Y::XMLText, nil]
133
133
  def prev_sibling
134
134
  node = document.current_transaction { |tx| yxml_element_prev_sibling(tx) }
135
135
  node&.document = document
@@ -199,7 +199,7 @@ module Y
199
199
  # @return [void]
200
200
  def slice!(*args)
201
201
  document.current_transaction do |tx| # rubocop:disable Metrics/BlockLength
202
- if args.size.zero?
202
+ if args.empty?
203
203
  raise ArgumentError,
204
204
  "Provide one of `index`, `range`, `start, length` as arguments"
205
205
  end
@@ -349,26 +349,26 @@ module Y
349
349
  # @!method yxml_element_first_child(tx)
350
350
  #
351
351
  # @param tx [Y::Transaction]
352
- # @return [Y::XMLElement|Y::XMLText]
352
+ # @return [Y::XMLElement, Y::XMLText]
353
353
 
354
354
  # @!method yxml_element_get_attribute(tx, name)
355
355
  #
356
356
  # @param tx [Y::Transaction]
357
357
  # @param name [String]
358
- # @return [String|nil]
358
+ # @return [String, nil]
359
359
 
360
360
  # @!method yxml_element_get(tx, index)
361
361
  #
362
362
  # @param tx [Y::Transaction]
363
363
  # @param index [Integer]
364
- # @return [Y::XMLElement|Y::XMLText|nil]
364
+ # @return [Y::XMLElement, Y::XMLText, nil]
365
365
 
366
366
  # @!method yxml_element_insert_attribute(tx, name, value)
367
367
  #
368
368
  # @param tx [Y::Transaction]
369
369
  # @param name [String]
370
370
  # @param value [String]
371
- # @return [String|nil]
371
+ # @return [String, nil]
372
372
 
373
373
  # @!method yxml_element_insert_element(tx, index, name)
374
374
  # Insert XML element into this XML element
@@ -389,7 +389,7 @@ module Y
389
389
  # @!method yxml_element_next_sibling(tx)
390
390
  #
391
391
  # @param tx [Y::Transaction]
392
- # @return [Y::XMLElement|XMLText|nil]
392
+ # @return [Y::XMLElement, XMLText, nil]
393
393
 
394
394
  # @!method yxml_element_observe(callback)
395
395
  #
@@ -398,12 +398,12 @@ module Y
398
398
 
399
399
  # @!method yxml_element_parent()
400
400
  #
401
- # @return [Y::XMLElement|nil]
401
+ # @return [Y::XMLElement, nil]
402
402
 
403
403
  # @!method yxml_element_prev_sibling(tx)
404
404
  #
405
405
  # @param tx [Y::Transaction]
406
- # @return [Y::XMLElement|XMLText|nil]
406
+ # @return [Y::XMLElement, XMLText, nil]
407
407
 
408
408
  # @!method yxml_element_push_element_back(tx, name)
409
409
  #
@@ -562,7 +562,7 @@ module Y
562
562
  #
563
563
  # @param index [Integer]
564
564
  # @param value [String, Float, Integer, Array, Hash, Boolean]
565
- # @param attrs [Hash|nil]
565
+ # @param attrs [Hash, nil]
566
566
  # @return [void]
567
567
  def insert(index, value, attrs = nil)
568
568
  document.current_transaction do |tx|
@@ -604,7 +604,7 @@ module Y
604
604
 
605
605
  # Return adjacent XMLElement or XMLText node (next)
606
606
  #
607
- # @return [Y::XMLElement|Y::XMLText|nil]
607
+ # @return [Y::XMLElement, Y::XMLText, nil]
608
608
  def next_sibling
609
609
  node = document.current_transaction { |tx| yxml_text_next_sibling(tx) }
610
610
  node.document = document
@@ -613,7 +613,7 @@ module Y
613
613
 
614
614
  # Return parent XMLElement
615
615
  #
616
- # @return [Y::XMLElement|nil]
616
+ # @return [Y::XMLElement, nil]
617
617
  def parent
618
618
  node = yxml_text_parent
619
619
  node.document = document
@@ -622,7 +622,7 @@ module Y
622
622
 
623
623
  # Return adjacent XMLElement or XMLText node (prev)
624
624
  #
625
- # @return [Y::XMLElement|Y::XMLText|nil]
625
+ # @return [Y::XMLElement, Y::XMLText, nil]
626
626
  def prev_sibling
627
627
  node = document.current_transaction { |tx| yxml_text_prev_sibling(tx) }
628
628
  node&.document = document
@@ -682,7 +682,7 @@ module Y
682
682
  # @return [void]
683
683
  def slice!(*args)
684
684
  document.current_transaction do |tx|
685
- if args.size.zero?
685
+ if args.empty?
686
686
  raise ArgumentError,
687
687
  "Provide one of `index`, `range`, `start, length` as arguments"
688
688
  end
@@ -742,7 +742,7 @@ module Y
742
742
  setter = method_name
743
743
  setter += "=" unless is_setter
744
744
  getter = method_name
745
- getter = getter.to_s.slice(0...-1).to_sym if is_setter
745
+ getter = getter.to_s.slice(0...-1)&.to_sym if is_setter
746
746
 
747
747
  define_singleton_method(setter.to_sym) do |new_val|
748
748
  document.current_transaction do |tx|
@@ -803,7 +803,7 @@ module Y
803
803
  #
804
804
  # @param tx [Y::Transaction]
805
805
  # @param name [String]
806
- # @return [String|nil]
806
+ # @return [String, nil]
807
807
 
808
808
  # @!method yxml_text_insert(tx, index, str)
809
809
  #
@@ -838,7 +838,7 @@ module Y
838
838
  #
839
839
  # @param tx [Y::Transaction]
840
840
  # @param index [Integer]
841
- # @param value [true|false|Float|Integer|Array|Hash]
841
+ # @param value [true, false, Float, Integer, Array, Hash]
842
842
  # @param attrs [Hash]
843
843
  # @return [void]
844
844
 
@@ -850,7 +850,7 @@ module Y
850
850
  # @!method yxml_text_next_sibling(tx)
851
851
  #
852
852
  # @param tx [Y::Transaction]
853
- # @return [Y::XMLElement|Y::XMLText|nil]
853
+ # @return [Y::XMLElement, Y::XMLText, nil]
854
854
 
855
855
  # @!method yxml_text_observe(callback)
856
856
  #
@@ -859,12 +859,12 @@ module Y
859
859
 
860
860
  # @!method yxml_text_parent
861
861
  #
862
- # @return [Y::XMLElement|nil]
862
+ # @return [Y::XMLElement, nil]
863
863
 
864
864
  # @!method yxml_text_prev_sibling(tx)
865
865
  #
866
866
  # @param tx [Y::Transaction]
867
- # @return [Y::XMLElement|Y::XMLText|nil]
867
+ # @return [Y::XMLElement, Y::XMLText, nil]
868
868
 
869
869
  # @!method yxml_text_push(tx, str)
870
870
  #
@@ -896,6 +896,245 @@ module Y
896
896
  #
897
897
  # @return [Y::Doc] The document this array belongs to
898
898
  attr_accessor :document
899
+
900
+ # Create a new XMLElement instance
901
+ #
902
+ # @param doc [Y::Doc]
903
+ def initialize(doc = nil)
904
+ @document = doc || Y::Doc.new
905
+
906
+ super()
907
+ end
908
+
909
+ # Retrieve node at index
910
+ #
911
+ # @param index [Integer]
912
+ # @return [Y::XMLElement, Y::XMLFragment, Y::XMLText, nil]
913
+ def [](index)
914
+ node = document.current_transaction { |tx| yxml_fragment_get(tx, index) }
915
+ node&.document = document
916
+ node
917
+ end
918
+
919
+ # Create a node at index
920
+ #
921
+ # @param index [Integer]
922
+ # @param name [String] Name of node, e.g. `<p />`
923
+ # @return [Y::XMLElement]
924
+ # rubocop:disable Lint/Void
925
+ def []=(index, name)
926
+ node = document.current_transaction do |tx|
927
+ yxml_fragment_insert(tx, index, name)
928
+ end
929
+ node.document = document
930
+ node
931
+ end
932
+ # rubocop:enable Lint/Void
933
+
934
+ # Retrieve first child
935
+ #
936
+ # @return [Y::XMLElement, Y::XMLFragment, Y::XMLText, nil]
937
+ def first_child
938
+ node = yxml_fragment_first_child
939
+ node&.document = document
940
+ node
941
+ end
942
+
943
+ # Retrieve child at index
944
+ #
945
+ # @param [Integer] index
946
+ # @param [String] tag
947
+ # @return [Y::XMLElement, Y::XMLFragment, Y::XMLText, nil]
948
+ def insert(index, tag)
949
+ document.current_transaction { |tx| yxml_fragment_insert(tx, index, tag) }
950
+ end
951
+
952
+ # Length of the fragment
953
+ #
954
+ # @return [Integer]
955
+ def length
956
+ document.current_transaction { |tx| yxml_fragment_len(tx) }
957
+ end
958
+
959
+ alias size length
960
+
961
+ # Retrieve parent element
962
+ #
963
+ # @return [Y::XMLElement, Y::XMLFragment, Y::XMLText, nil]
964
+ def parent
965
+ node = yxml_fragment_parent
966
+ node.document = document
967
+ node
968
+ end
969
+
970
+ # Creates a new child an inserts at the end of the children list
971
+ #
972
+ # @param name [String]
973
+ # @return [Y::XMLElement]
974
+ def <<(name)
975
+ xml_element = document.current_transaction do |tx|
976
+ yxml_fragment_push_back(tx, name)
977
+ end
978
+ xml_element.document = document
979
+ xml_element
980
+ end
981
+
982
+ alias push <<
983
+
984
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
985
+
986
+ # Removes one or more children from XML Fragment
987
+ #
988
+ # @example Removes a single element
989
+ # doc = Y::Doc.new
990
+ #
991
+ # xml_fragment = doc.get_xml_fragment("my xml fragment")
992
+ # xml_fragment << "A"
993
+ # xml_fragment << "B"
994
+ # xml_fragment << "C"
995
+ #
996
+ # xml_fragment.slice!(1)
997
+ #
998
+ # xml_fragment.to_s # <UNDEFINED><A></A><C></C></UNDEFINED>
999
+ #
1000
+ # @overload slice!(n)
1001
+ # Removes nth node from child list
1002
+ #
1003
+ # @overload slice!(start, length)
1004
+ # Removes a range of nodes
1005
+ #
1006
+ # @overload slice!(range)
1007
+ # Removes a range of nodes
1008
+ #
1009
+ # @return [void]
1010
+ def slice!(*args)
1011
+ document.current_transaction do |tx| # rubocop:disable Metrics/BlockLength
1012
+ if args.empty?
1013
+ raise ArgumentError,
1014
+ "Provide one of `index`, `range`, `start, length` as arguments"
1015
+ end
1016
+
1017
+ if args.size == 1
1018
+ arg = args.first
1019
+
1020
+ if arg.is_a?(Range)
1021
+ if arg.exclude_end?
1022
+ yxml_fragment_remove_range(tx, arg.first,
1023
+ arg.last - arg.first)
1024
+ end
1025
+ unless arg.exclude_end?
1026
+ yxml_fragment_remove_range(tx, arg.first,
1027
+ arg.last + 1 - arg.first)
1028
+ end
1029
+ return nil
1030
+ end
1031
+
1032
+ if arg.is_a?(Numeric)
1033
+ yxml_fragment_remove_range(tx, arg.to_int, 1)
1034
+ return nil
1035
+ end
1036
+ end
1037
+
1038
+ if args.size == 2
1039
+ first, second = args
1040
+
1041
+ if first.is_a?(Numeric) && second.is_a?(Numeric)
1042
+ yxml_fragment_remove_range(tx, first, second)
1043
+ return nil
1044
+ end
1045
+ end
1046
+
1047
+ raise ArgumentError, "Please check your arguments, can't slice."
1048
+ end
1049
+ end
1050
+
1051
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
1052
+
1053
+ # Traverse over the successors of the current XML element and return
1054
+ # a flat representation of all successors.
1055
+ #
1056
+ # @return [Array<Y::XMLElement, Y::XMLFragment, Y::XMLText]
1057
+ def successors
1058
+ document.current_transaction { |tx| yxml_fragment_successors(tx) }
1059
+ end
1060
+
1061
+ # Returns string representation of XMLFragment
1062
+ #
1063
+ # @return [String]
1064
+ def to_s
1065
+ document.current_transaction { |tx| yxml_fragment_to_s(tx) }
1066
+ end
1067
+
1068
+ # Creates a new node and puts it in front of the child list
1069
+ #
1070
+ # @param name [String]
1071
+ # @return [Y::XMLElement]
1072
+ def unshift(name)
1073
+ xml_element = document.current_transaction do |tx|
1074
+ yxml_fragment_push_front(tx, name)
1075
+ end
1076
+ xml_element.document = document
1077
+ xml_element
1078
+ end
1079
+
1080
+ # @!method yxml_fragment_first_child
1081
+ #
1082
+ # @return [Y::XMLElement, Y::XMLFragment, Y::XMLText, nil]
1083
+
1084
+ # @!method yxml_fragment_get(tx, index)
1085
+ #
1086
+ # @param [Y::Transaction] tx
1087
+ # @param [Integer] index
1088
+ # @return [Y::XMLElement, Y::XMLFragment, Y::XMLText, nil]
1089
+
1090
+ # @!method yxml_fragment_insert(tx, index, tag)
1091
+ #
1092
+ # @param tx [Y::Transaction]
1093
+ # @param [Integer] index
1094
+ # @param [String] tag
1095
+ # @return [Y::XMLElement, Y::XMLFragment, Y::XMLText, nil]
1096
+
1097
+ # @!method yxml_fragment_len(tx)
1098
+ #
1099
+ # @param tx [Y::Transaction]
1100
+ # @return [Integer]
1101
+
1102
+ # @!method yxml_fragment_parent
1103
+ #
1104
+ # @return [Y::XMLElement, Y::XMLFragment, Y::XMLText, nil]
1105
+
1106
+ # @!method yxml_fragment_push_back(tx, tag)
1107
+ #
1108
+ # @param tx [Y::Transaction]
1109
+ # @param [String] tag
1110
+ # @return [Y::XMLElement]
1111
+
1112
+ # @!method yxml_fragment_push_front(tx, tag)
1113
+ #
1114
+ # @param tx [Y::Transaction]
1115
+ # @param [String] tag
1116
+ # @return [Y::XMLElement]
1117
+
1118
+ # @!method yxml_fragment_remove(tx, index)
1119
+ #
1120
+ # @param tx [Y::Transaction]
1121
+ # @param [Integer] index
1122
+
1123
+ # @!method yxml_fragment_remove_range(tx, index, length)
1124
+ #
1125
+ # @param tx [Y::Transaction]
1126
+ # @param [Integer] index
1127
+ # @param [Integer] length
1128
+
1129
+ # @!method yxml_fragment_successors(tx)
1130
+ #
1131
+ # @param tx [Y::Transaction]
1132
+ # @return [Array<Y::XMLElement, Y::XMLFragment, Y::XMLText>]
1133
+
1134
+ # @!method yxml_fragment_to_s(tx)
1135
+ #
1136
+ # @param tx [Y::Transaction]
1137
+ # @return [String]
899
1138
  end
900
1139
 
901
1140
  # rubocop:enable Metrics/ClassLength
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: y-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.5.0
5
5
  platform: x86_64-darwin
6
6
  authors:
7
7
  - Hannes Moser
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-01 00:00:00.000000000 Z
11
+ date: 2023-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -78,7 +78,6 @@ extra_rdoc_files: []
78
78
  files:
79
79
  - ext/yrb/Cargo.toml
80
80
  - ext/yrb/extconf.rb
81
- - ext/yrb/src/awareness.rs
82
81
  - ext/yrb/src/lib.rs
83
82
  - ext/yrb/src/utils.rs
84
83
  - ext/yrb/src/yany.rs