nokolexbor 0.3.6 → 0.3.7

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: 29411076a95eae20060101aa8a270bfe53a48eda3b6e58cfad6ebe22b184049c
4
- data.tar.gz: 920536ad4f69a635cfec9a6dea4d8bbe746c7c97d74c1b1daa6b22c41856d201
3
+ metadata.gz: 25a206e02eaf74545bf1e7abe7e43a53e38fd8626b337e8de7d6c207e352a686
4
+ data.tar.gz: 2b9f7c8a339b2618dbb2de5824b249f0a8fa690713028a9e22b8627a8bb0163a
5
5
  SHA512:
6
- metadata.gz: d6ca49aa873ee254caf034600fbbb9384a2a4efaa86422e992a7fbb7970107af20541c4309e582c6f8863353209d36cd6e5d56fdb19b52fd54a233a4419202ea
7
- data.tar.gz: f4c9413c2cd8683e6cf111d1c966a8511d4d605ec30008f595d2c05b402b028dc8f889c9480d3ff43b0f380e84861b2384c915f9f9cca68b6ad8f510a58a0b0a
6
+ metadata.gz: 70e579aa1e64ae9cfcf71dd2d0bf3b77b634b69764d43c04aaa02b6db0c5b26cb992d0094ad4b2b9177ca2be46c6b32df38381224bd579bfb722c538075b436e
7
+ data.tar.gz: c89997e12178393f171bb5e3735346d99ee67047fb985ec02b08e9433aadc6f18d68278a5256c99ab7174ddd436f9bb49fb97a97808923205803097b083f7ed3
@@ -178,6 +178,20 @@ nl_attribute_next(VALUE self)
178
178
  return nl_rb_node_create(attr->next, nl_rb_document_get(self));
179
179
  }
180
180
 
181
+ static VALUE
182
+ nl_attribute_inspect(VALUE self)
183
+ {
184
+ VALUE c = rb_class_name(CLASS_OF(self));
185
+ lxb_dom_node_t *node = nl_rb_node_unwrap(self);
186
+ lxb_dom_attr_t *attr = lxb_dom_interface_attr(node);
187
+ size_t len;
188
+ lxb_char_t *attr_value = lxb_dom_attr_value(attr, &len);
189
+
190
+ return rb_sprintf("#<%" PRIsVALUE " %s=\"%s\">", c,
191
+ lxb_dom_attr_qualified_name(attr, &len),
192
+ attr_value == NULL ? "" : attr_value);
193
+ }
194
+
181
195
  void Init_nl_attribute(void)
182
196
  {
183
197
  cNokolexborAttribute = rb_define_class_under(mNokolexbor, "Attribute", cNokolexborNode);
@@ -191,6 +205,7 @@ void Init_nl_attribute(void)
191
205
  rb_define_method(cNokolexborAttribute, "parent", nl_attribute_parent, 0);
192
206
  rb_define_method(cNokolexborAttribute, "previous", nl_attribute_previous, 0);
193
207
  rb_define_method(cNokolexborAttribute, "next", nl_attribute_next, 0);
208
+ rb_define_method(cNokolexborAttribute, "inspect", nl_attribute_inspect, 0);
194
209
 
195
210
  rb_define_alias(cNokolexborAttribute, "node_name", "name");
196
211
  rb_define_alias(cNokolexborAttribute, "node_name=", "name=");
@@ -9,6 +9,7 @@ extern VALUE mNokolexbor;
9
9
  extern VALUE cNokolexborDocument;
10
10
  extern VALUE cNokolexborText;
11
11
  extern VALUE cNokolexborComment;
12
+ extern VALUE cNokolexborCData;
12
13
  extern VALUE cNokolexborProcessingInstruction;
13
14
  extern VALUE cNokolexborNodeSet;
14
15
  extern VALUE cNokolexborDocumentFragment;
@@ -39,7 +40,7 @@ nl_rb_node_create(lxb_dom_node_t *node, VALUE rb_document)
39
40
  rb_class = cNokolexborText;
40
41
  break;
41
42
  case LXB_DOM_NODE_TYPE_CDATA_SECTION:
42
- rb_class = cNokolexborCharacterData;
43
+ rb_class = cNokolexborCData;
43
44
  break;
44
45
  // case LXB_DOM_NODE_TYPE_ENTITY_REFERENCE:
45
46
  // break;
@@ -1106,6 +1107,32 @@ nl_node_clone(VALUE self)
1106
1107
  return nl_rb_node_create(clone, nl_rb_document_get(self));
1107
1108
  }
1108
1109
 
1110
+ static VALUE
1111
+ nl_node_inspect(int argc, VALUE *argv, VALUE self)
1112
+ {
1113
+ lxb_dom_node_t *node = nl_rb_node_unwrap(self);
1114
+ if (node->type == LXB_DOM_NODE_TYPE_DOCUMENT) {
1115
+ return rb_call_super(argc, argv);
1116
+ }
1117
+
1118
+ VALUE c = rb_class_name(CLASS_OF(self));
1119
+ lexbor_str_t str = {0};
1120
+ lxb_status_t status = lxb_html_serialize_str(node, &str);
1121
+ if (status != LXB_STATUS_OK) {
1122
+ if (str.data != NULL) {
1123
+ lexbor_str_destroy(&str, node->owner_document->text, false);
1124
+ }
1125
+ return rb_call_super(argc, argv);
1126
+ }
1127
+
1128
+ if (str.data != NULL) {
1129
+ VALUE ret = rb_sprintf("#<%" PRIsVALUE " %s>", c, str.data);
1130
+ lexbor_str_destroy(&str, node->owner_document->text, false);
1131
+ return ret;
1132
+ }
1133
+ return rb_call_super(argc, argv);
1134
+ }
1135
+
1109
1136
  void Init_nl_node(void)
1110
1137
  {
1111
1138
  cNokolexborNode = rb_define_class_under(mNokolexbor, "Node", rb_cObject);
@@ -1148,6 +1175,7 @@ void Init_nl_node(void)
1148
1175
  rb_define_method(cNokolexborNode, "first_element_child", nl_node_first_element_child, 0);
1149
1176
  rb_define_method(cNokolexborNode, "last_element_child", nl_node_last_element_child, 0);
1150
1177
  rb_define_method(cNokolexborNode, "clone", nl_node_clone, 0);
1178
+ rb_define_method(cNokolexborNode, "inspect", nl_node_inspect, -1);
1151
1179
 
1152
1180
  rb_define_alias(cNokolexborNode, "attr", "[]");
1153
1181
  rb_define_alias(cNokolexborNode, "get_attribute", "[]");
@@ -196,6 +196,10 @@ module Nokolexbor
196
196
  end
197
197
  end
198
198
 
199
+ def inspect
200
+ "[#{map(&:inspect).join(', ')}]"
201
+ end
202
+
199
203
  private
200
204
 
201
205
  IMPLIED_XPATH_CONTEXTS = [".//", "self::"].freeze # :nodoc:
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nokolexbor
4
- VERSION = '0.3.6'
4
+ VERSION = '0.3.7'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nokolexbor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yicheng Zhou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-04 00:00:00.000000000 Z
11
+ date: 2023-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler