xpather 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/ext/xpather/xpather.c +11 -14
  2. metadata +1 -1
@@ -40,11 +40,13 @@ VALUE search(VALUE self, VALUE xpathExpr)
40
40
 
41
41
  if (size == 1) {
42
42
  results = rb_str_new2(xmlNodeGetContent(nodes->nodeTab[0]));
43
- } else {
43
+ } else if (size > 1) {
44
44
  for (i = 0; i < size; ++i) {
45
45
  cur = nodes->nodeTab[i];
46
46
  rb_ary_push(results, rb_str_new2(xmlNodeGetContent(cur)));
47
47
  }
48
+ } else {
49
+ return Qnil;
48
50
  }
49
51
 
50
52
  xmlXPathFreeObject(xpathObj);
@@ -53,31 +55,27 @@ VALUE search(VALUE self, VALUE xpathExpr)
53
55
  return results;
54
56
  }
55
57
 
56
- static VALUE initialize(VALUE self, VALUE filename)
58
+ static VALUE initialize(VALUE self, VALUE xmlStr)
57
59
  {
58
- rb_iv_set(self, "@filename", filename);
60
+ rb_iv_set(self, "@xml_str", xmlStr);
59
61
  return self;
60
62
  }
61
63
 
62
- static VALUE filename(VALUE self)
63
- {
64
- return rb_iv_get(self, "@filename");
65
- }
66
-
67
- VALUE constructor(VALUE self, VALUE filename)
64
+ VALUE constructor(VALUE self, VALUE xmlStr)
68
65
  {
69
66
  xmlDocPtr doc;
67
+ const char *xmlCStr = StringValueCStr(xmlStr);
70
68
  VALUE argv[1];
71
69
  VALUE t_data;
72
70
 
73
- doc = xmlParseMemory(StringValueCStr(filename), strlen(StringValueCStr(filename)));
71
+ doc = xmlParseMemory(xmlCStr, strlen(xmlCStr));
74
72
  if (doc == NULL) {
75
- fprintf(stderr, "Error: unable to parse file \"%s\"\n", StringValueCStr(filename));
76
- return -1;
73
+ fprintf(stderr, "Error: unable to parse xml\n");
74
+ return Qnil;
77
75
  }
78
76
 
79
77
  t_data = Data_Wrap_Struct(self, 0, xml_free, doc);
80
- argv[0] = filename;
78
+ argv[0] = xmlStr;
81
79
  rb_obj_call_init(t_data, 1, argv);
82
80
  return t_data;
83
81
  }
@@ -87,6 +85,5 @@ void Init_xpather(void)
87
85
  VALUE klass = rb_define_class("XPather", rb_cObject);
88
86
  rb_define_singleton_method(klass, "new", constructor, 1);
89
87
  rb_define_method(klass, "initialize", initialize, 1);
90
- rb_define_method(klass, "filename", filename, 0);
91
88
  rb_define_method(klass, "search", search, 1);
92
89
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xpather
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: