sucker 1.3.0 → 1.3.1

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.
@@ -17,6 +17,14 @@ module Sucker
17
17
  self.code = response.code
18
18
  end
19
19
 
20
+ # A shorthand that yields each match to a block
21
+ #
22
+ # response.each('Item') { |item| process_item(item) }
23
+ #
24
+ def each(path)
25
+ find(path).each { |match| yield match }
26
+ end
27
+
20
28
  # Returns an array of errors in the reponse
21
29
  def errors
22
30
  find('Error')
@@ -24,7 +32,6 @@ module Sucker
24
32
 
25
33
  # Queries an xpath and returns an array of matching nodes
26
34
  #
27
- # response = worker.get
28
35
  # items = response.find('Item')
29
36
  #
30
37
  def find(path)
@@ -38,6 +45,14 @@ module Sucker
38
45
  errors.count > 0
39
46
  end
40
47
 
48
+ # A shorthand that yields matches to a block and collects returned values
49
+ #
50
+ # descriptions = response.map('Item') { |item| build_description(item) }
51
+ #
52
+ def map(path)
53
+ find(path).map { |match| yield match }
54
+ end
55
+
41
56
  # Parses response into a simple hash
42
57
  def to_hash
43
58
  Hash.from_xml(xml)
@@ -151,7 +151,7 @@ x
151
151
  8
152
152
  Response
153
153
  i
154
- 126
154
+ 154
155
155
  5
156
156
  66
157
157
  5
@@ -212,21 +212,35 @@ i
212
212
  6
213
213
  4
214
214
  15
215
- 5
215
+ 99
216
216
  7
217
217
  11
218
218
  7
219
- 9
219
+ 12
220
+ 65
221
+ 67
222
+ 49
223
+ 5
224
+ 0
225
+ 49
226
+ 6
227
+ 4
228
+ 15
229
+ 5
230
+ 7
231
+ 13
232
+ 7
233
+ 11
220
234
  47
221
235
  49
222
- 12
236
+ 14
223
237
  2
224
238
  15
225
239
  99
226
240
  7
227
- 13
241
+ 15
228
242
  7
229
- 14
243
+ 16
230
244
  65
231
245
  67
232
246
  49
@@ -238,9 +252,23 @@ i
238
252
  15
239
253
  99
240
254
  7
255
+ 17
256
+ 7
257
+ 18
258
+ 65
259
+ 67
260
+ 49
261
+ 5
262
+ 0
263
+ 49
264
+ 6
265
+ 4
241
266
  15
267
+ 99
242
268
  7
243
- 16
269
+ 19
270
+ 7
271
+ 20
244
272
  65
245
273
  67
246
274
  49
@@ -252,9 +280,9 @@ i
252
280
  15
253
281
  99
254
282
  7
255
- 17
283
+ 21
256
284
  7
257
- 18
285
+ 22
258
286
  65
259
287
  67
260
288
  49
@@ -266,9 +294,9 @@ i
266
294
  15
267
295
  99
268
296
  7
269
- 19
297
+ 23
270
298
  7
271
- 20
299
+ 24
272
300
  65
273
301
  67
274
302
  49
@@ -288,7 +316,7 @@ I
288
316
  0
289
317
  n
290
318
  p
291
- 21
319
+ 25
292
320
  x
293
321
  4
294
322
  body
@@ -372,7 +400,7 @@ f
372
400
  I
373
401
  0
374
402
  I
375
- 40
403
+ 4f
376
404
  I
377
405
  1
378
406
  I
@@ -380,7 +408,7 @@ I
380
408
  I
381
409
  f
382
410
  I
383
- 40
411
+ 4f
384
412
  I
385
413
  10
386
414
  I
@@ -402,6 +430,118 @@ x
402
430
  15
403
431
  add_defn_method
404
432
  x
433
+ 4
434
+ each
435
+ M
436
+ 1
437
+ n
438
+ n
439
+ x
440
+ 4
441
+ each
442
+ i
443
+ 13
444
+ 5
445
+ 20
446
+ 0
447
+ 47
448
+ 49
449
+ 0
450
+ 1
451
+ 56
452
+ 1
453
+ 50
454
+ 2
455
+ 0
456
+ 11
457
+ I
458
+ 3
459
+ I
460
+ 1
461
+ I
462
+ 1
463
+ I
464
+ 1
465
+ n
466
+ p
467
+ 3
468
+ x
469
+ 4
470
+ find
471
+ M
472
+ 1
473
+ p
474
+ 2
475
+ x
476
+ 9
477
+ for_block
478
+ t
479
+ n
480
+ x
481
+ 4
482
+ each
483
+ i
484
+ 9
485
+ 57
486
+ 19
487
+ 0
488
+ 15
489
+ 20
490
+ 0
491
+ 60
492
+ 1
493
+ 11
494
+ I
495
+ 3
496
+ I
497
+ 1
498
+ I
499
+ 1
500
+ I
501
+ 1
502
+ n
503
+ p
504
+ 0
505
+ p
506
+ 3
507
+ I
508
+ 0
509
+ I
510
+ 19
511
+ I
512
+ 9
513
+ x
514
+ 45
515
+ /Users/snl/code/sucker/lib/sucker/response.rb
516
+ p
517
+ 1
518
+ x
519
+ 5
520
+ match
521
+ x
522
+ 4
523
+ each
524
+ p
525
+ 5
526
+ I
527
+ -1
528
+ I
529
+ 18
530
+ I
531
+ 0
532
+ I
533
+ 19
534
+ I
535
+ d
536
+ x
537
+ 45
538
+ /Users/snl/code/sucker/lib/sucker/response.rb
539
+ p
540
+ 1
541
+ x
542
+ 4
543
+ path
544
+ x
405
545
  6
406
546
  errors
407
547
  M
@@ -444,11 +584,11 @@ p
444
584
  I
445
585
  -1
446
586
  I
447
- 15
587
+ 1d
448
588
  I
449
589
  0
450
590
  I
451
- 16
591
+ 1e
452
592
  I
453
593
  9
454
594
  x
@@ -562,7 +702,7 @@ p
562
702
  I
563
703
  0
564
704
  I
565
- 1f
705
+ 26
566
706
  I
567
707
  d
568
708
  x
@@ -581,11 +721,11 @@ p
581
721
  I
582
722
  -1
583
723
  I
584
- 1e
724
+ 25
585
725
  I
586
726
  0
587
727
  I
588
- 1f
728
+ 26
589
729
  I
590
730
  15
591
731
  x
@@ -649,11 +789,11 @@ p
649
789
  I
650
790
  -1
651
791
  I
652
- 25
792
+ 2c
653
793
  I
654
794
  0
655
795
  I
656
- 26
796
+ 2d
657
797
  I
658
798
  a
659
799
  x
@@ -662,6 +802,118 @@ x
662
802
  p
663
803
  0
664
804
  x
805
+ 3
806
+ map
807
+ M
808
+ 1
809
+ n
810
+ n
811
+ x
812
+ 3
813
+ map
814
+ i
815
+ 13
816
+ 5
817
+ 20
818
+ 0
819
+ 47
820
+ 49
821
+ 0
822
+ 1
823
+ 56
824
+ 1
825
+ 50
826
+ 2
827
+ 0
828
+ 11
829
+ I
830
+ 3
831
+ I
832
+ 1
833
+ I
834
+ 1
835
+ I
836
+ 1
837
+ n
838
+ p
839
+ 3
840
+ x
841
+ 4
842
+ find
843
+ M
844
+ 1
845
+ p
846
+ 2
847
+ x
848
+ 9
849
+ for_block
850
+ t
851
+ n
852
+ x
853
+ 3
854
+ map
855
+ i
856
+ 9
857
+ 57
858
+ 19
859
+ 0
860
+ 15
861
+ 20
862
+ 0
863
+ 60
864
+ 1
865
+ 11
866
+ I
867
+ 3
868
+ I
869
+ 1
870
+ I
871
+ 1
872
+ I
873
+ 1
874
+ n
875
+ p
876
+ 0
877
+ p
878
+ 3
879
+ I
880
+ 0
881
+ I
882
+ 35
883
+ I
884
+ 9
885
+ x
886
+ 45
887
+ /Users/snl/code/sucker/lib/sucker/response.rb
888
+ p
889
+ 1
890
+ x
891
+ 5
892
+ match
893
+ x
894
+ 3
895
+ map
896
+ p
897
+ 5
898
+ I
899
+ -1
900
+ I
901
+ 34
902
+ I
903
+ 0
904
+ I
905
+ 35
906
+ I
907
+ d
908
+ x
909
+ 45
910
+ /Users/snl/code/sucker/lib/sucker/response.rb
911
+ p
912
+ 1
913
+ x
914
+ 4
915
+ path
916
+ x
665
917
  7
666
918
  to_hash
667
919
  M
@@ -709,11 +961,11 @@ p
709
961
  I
710
962
  -1
711
963
  I
712
- 2a
964
+ 39
713
965
  I
714
966
  0
715
967
  I
716
- 2b
968
+ 3a
717
969
  I
718
970
  a
719
971
  x
@@ -767,11 +1019,11 @@ p
767
1019
  I
768
1020
  -1
769
1021
  I
770
- 34
1022
+ 43
771
1023
  I
772
1024
  0
773
1025
  I
774
- 35
1026
+ 44
775
1027
  I
776
1028
  9
777
1029
  x
@@ -838,11 +1090,11 @@ p
838
1090
  I
839
1091
  -1
840
1092
  I
841
- 3c
1093
+ 4b
842
1094
  I
843
1095
  0
844
1096
  I
845
- 3d
1097
+ 4c
846
1098
  I
847
1099
  12
848
1100
  x
@@ -851,7 +1103,7 @@ x
851
1103
  p
852
1104
  0
853
1105
  p
854
- 21
1106
+ 25
855
1107
  I
856
1108
  2
857
1109
  I
@@ -867,23 +1119,23 @@ f
867
1119
  I
868
1120
  20
869
1121
  I
870
- 15
1122
+ 18
871
1123
  I
872
1124
  2e
873
1125
  I
874
- 1e
1126
+ 1d
875
1127
  I
876
1128
  3c
877
1129
  I
878
- 22
1130
+ 25
879
1131
  I
880
- 46
1132
+ 4a
881
1133
  I
882
- 25
1134
+ 29
883
1135
  I
884
1136
  54
885
1137
  I
886
- 2a
1138
+ 2c
887
1139
  I
888
1140
  62
889
1141
  I
@@ -891,9 +1143,17 @@ I
891
1143
  I
892
1144
  70
893
1145
  I
894
- 3c
1146
+ 39
895
1147
  I
896
1148
  7e
1149
+ I
1150
+ 43
1151
+ I
1152
+ 8c
1153
+ I
1154
+ 4b
1155
+ I
1156
+ 9a
897
1157
  x
898
1158
  45
899
1159
  /Users/snl/code/sucker/lib/sucker/response.rb