sergio 0.0.2 → 0.0.3

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.
@@ -50,15 +50,6 @@ module Sergio
50
50
  v
51
51
  end
52
52
 
53
- #FROM https://gist.github.com/6391/62b6aae9206abe7b3fea6d4659e4c246f8cf7632
54
- def hash_recursive_merge(lval, rval)
55
- r = {}
56
- v = lval.merge(rval) do |key, oldval, newval|
57
- r[key] = oldval.class == Hash && newval.class == Hash ? hash_recursive_merge(oldval, newval) : newval
58
- end
59
- v
60
- end
61
-
62
53
  def hash_recursive_append(lval, rval)
63
54
  r = {}
64
55
  v = lval.merge(rval) do |key, oldval, newval|
@@ -85,10 +76,4 @@ module Sergio
85
76
  v
86
77
  end
87
78
  end
88
-
89
- def remove_empty_hashes(hash)
90
- hash.delete_if do |k,v|
91
- true
92
- end
93
- end
94
79
  end
@@ -7,8 +7,9 @@ class SergioSax < Nokogiri::XML::SAX::Document
7
7
  end
8
8
 
9
9
  def start_element(name, attrs = [])
10
+ attrs = Hash[*attrs.flatten]
10
11
  @stack << [name, attrs]
11
- if current_configs = @object.class.sergio_config.get_element_configs(@stack.clone)
12
+ if current_configs = @object.class.sergio_config.get_element_configs(@stack)
12
13
  current_configs.each do |c|
13
14
  if c.aggregate_element
14
15
  @parent_callbacks << lambda do
@@ -21,7 +22,7 @@ class SergioSax < Nokogiri::XML::SAX::Document
21
22
 
22
23
  def characters(string)
23
24
  name, attrs = @stack.last
24
- attrs << ['@text', string]
25
+ attrs['@text'] = attrs.fetch('@text', '') + string
25
26
  end
26
27
 
27
28
  def cdata_block(string)
@@ -29,22 +30,20 @@ class SergioSax < Nokogiri::XML::SAX::Document
29
30
  end
30
31
 
31
32
  def end_element(name)
32
- current_configs = @object.class.sergio_config.get_element_configs(@stack.clone)
33
+ current_configs = @object.class.sergio_config.get_element_configs(@stack)
33
34
  name, attrs = @stack.pop
34
35
  if current_configs
35
36
  current_configs.each do |c|
36
37
  attr = c.options[:attribute]
37
- val = attrs.assoc(attr)
38
+ val = attrs[attr]
38
39
  callback = c.callback
39
40
 
40
41
  if val && !c.aggregate_element
41
- val = val[1]
42
42
  r = if callback.arity == 1
43
43
  callback.call(val)
44
44
  elsif callback.arity == 2
45
- h = Hash[*attrs.flatten]
46
- h.delete('@text')
47
- callback.call(val, h)
45
+ attrs.delete('@text')
46
+ callback.call(val, attrs)
48
47
  end
49
48
 
50
49
  #only builds parent elements if at least one of their child elements has a match
@@ -1,3 +1,3 @@
1
1
  module Sergio
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,42 @@
1
+ <entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:service="http://activitystrea.ms/service-provider" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:media="http://purl.org/syndication/atommedia" xmlns:geo="http://www.georss.org/georss" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:gnip="http://www.gnip.com/schemas/2010">
2
+ <id>z13ocjxg0rnfj1kgh04cejqrswjgx1fopzs0k</id>
3
+ <published>2011-12-13T16:38:37+00:00</published>
4
+ <updated>2011-12-13T16:38:38+00:00</updated>
5
+ <title type="text/plain">Jay M posted a bookmark on Google+</title>
6
+ <category term="BookmarkPosted" label="Bookmark Posted"/>
7
+ <link rel="alternate" type="text/html" href="https://plus.google.com/115224273541109110117/posts/QfsSsHEmF27"/>
8
+ <source>
9
+ <link rel="self" type="application/json" href="https://www.googleapis.com/plus/v1/activities?query=Christmas&amp;orderBy=recent&amp;maxResults=20&amp;key=AIzaSyCl4y-dm-Nzf8zPdBYjQUSN0xbxE7JLCRI"/>
10
+ <title>Google - Plus - Keyword Search - Christmas</title>
11
+ <updated>2011-12-13T19-03-49Z</updated>
12
+ <gnip:rule>Christmas</gnip:rule>
13
+ </source>
14
+ <service:provider>
15
+ <name>Google</name>
16
+ <uri>plus.google.com</uri>
17
+ </service:provider>
18
+ <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
19
+ <activity:object>
20
+ <activity:object-type>http://activitystrea.ms/schema/1.0/bookmark</activity:object-type>
21
+ <id>object:z13ocjxg0rnfj1kgh04cejqrswjgx1fopzs0k</id>
22
+ <title type="text/html">www.militaryweddingdiscounts.com &#xBB; Blog Archive &#xBB; Second Day of Christmas &#x2013; Jay Mountford Photography</title>
23
+ <content type="text/html">Second Day of Christmas &#x2013; Jay Mountford Photography. Posted by Emma &#x2665; - December 13th, 2011. Name: Jay Mountford. Company name: Jay Mountford Photography. &#x2665; Favourite Christmas Song: That&amp;#39;s a toug...</content>
24
+ <subtitle type="text/html">Oooo looky looky - I&amp;#39;m talking about some amusing Christmas wishes over on Military Wedding today!&lt;br /&gt;&lt;br /&gt;#Christmas #Wedding #Military #Photography</subtitle>
25
+ <link rel="alternate" type="text/html" href="https://plus.google.com/115224273541109110117/posts/QfsSsHEmF27"/>
26
+ <link rel="enclosure" type="text/html" href="http://militaryweddingdiscounts.com/second-day-of-christmas-jay-mountford-photography/" title="www.militaryweddingdiscounts.com &#xBB; Blog Archive &#xBB; Second Day of Christmas &#x2013; Jay Mountford Photography"/>
27
+ <link rel="enclosure" type="image/jpeg" href="http://militaryweddingdiscounts.com/wp-content/uploads/2011/12/JayMountford12doc-1024x819.png" media:width="1024" media:height="819"/>
28
+ <gnip:statistics favoriteCount="0"/>
29
+ </activity:object>
30
+ <author>
31
+ <name>Jay M</name>
32
+ <uri>https://plus.google.com/115224273541109110117</uri>
33
+ </author>
34
+ <activity:actor>
35
+ <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
36
+ <link rel="alternate" type="html" length="0" href="https://plus.google.com/115224273541109110117"/>
37
+ <id>115224273541109110117</id>
38
+ </activity:actor>
39
+ <gnip:matching_rules>
40
+ <gnip:matching_rule rel="source">Christmas</gnip:matching_rule>
41
+ </gnip:matching_rules>
42
+ </entry>
@@ -62,32 +62,6 @@ describe Sergio::HashMethods do
62
62
  end
63
63
  end
64
64
 
65
- context 'hash_recursive_merge' do
66
- before do
67
- @s = Class.new do
68
- include Sergio::HashMethods
69
- end.new
70
- end
71
-
72
- it 'merges subhashes together' do
73
- h1 = {:thing => {'guy' => 'cool'}}
74
- h2 = {:thing => {'guys' => 'cool'}}
75
- @s.hash_recursive_merge(h1, h2).should == {:thing => {'guy' => 'cool', 'guys' => 'cool'}}
76
- end
77
-
78
- it 'replaces intersecting key values with rightmost hash argument value' do
79
- h1 = {:thing => {'guy' => 'cool'}}
80
- h2 = {:thing => {'guy' => 'cools'}}
81
- @s.hash_recursive_merge(h1, h2).should == {:thing => {'guy' => 'cools'}}
82
- end
83
-
84
- it 'merges new key values into existing hash if one is present' do
85
- h1 = {:thing => {'guy' => 'cool'}}
86
- h2 = {:thing => {'neat' => 'cools'}}
87
- @s.hash_recursive_merge(h1, h2).should == {:thing => {'guy' => 'cool', 'neat' => 'cools'}}
88
- end
89
- end
90
-
91
65
  context 'hash_recursive_append' do
92
66
  before do
93
67
  @s = Class.new do
@@ -38,14 +38,15 @@ describe Sergio do
38
38
  end
39
39
  end
40
40
  end
41
- @xml = '<a>
42
- <b></b>
43
- <b><f>a</f></b>
44
- <b>he</b>
45
- <c>a</c>
46
- <c>
47
- <e>e</e>
48
- </c>
41
+ @xml = '
42
+ <a>
43
+ <b></b>
44
+ <b><f>a</f></b>
45
+ <b>he</b>
46
+ <c>a</c>
47
+ <c>
48
+ <e>e</e>
49
+ </c>
49
50
  </a>'
50
51
  h = s.new.parse(@xml)
51
52
  h.should == {'a' => {'b' => [{'f' => 'a'}, {'e' => 'e'}]}}
@@ -269,7 +270,7 @@ describe Sergio do
269
270
 
270
271
  @xml = '<a y="what"><b>hi</b></a>'
271
272
  @hash = s.new.parse(@xml)
272
- @hash['a']['b'].should == {'c' => 'what'}
273
+ @hash['a']['b'].should == 'hi'
273
274
  end
274
275
  end
275
276
 
@@ -291,4 +292,18 @@ describe Sergio do
291
292
  v.should == {'thing' => [{'stuff' => '1'}, {'stuff' => '2'}]}
292
293
  end
293
294
  end
295
+
296
+ it 'properly parses elements which make multiple calls to SergioSax#characters' do
297
+ s = new_sergio do
298
+ element 'entry' do
299
+ element 'activity:object', 'object' do
300
+ element 'subtitle'
301
+ end
302
+ end
303
+ end
304
+
305
+ parsed_d = s.new.parse(File.read(File.dirname(__FILE__) + '/../support/weird_unicode.xml'))
306
+ expected = "Oooo looky looky - I&#39;m talking about some amusing Christmas wishes over on Military Wedding today!<br /><br />#Christmas #Wedding #Military #Photography"
307
+ parsed_d['entry']['object']['subtitle'].should == expected
308
+ end
294
309
  end
metadata CHANGED
@@ -1,61 +1,57 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sergio
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
4
5
  prerelease:
5
- version: 0.0.2
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Max Justus Spransy
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-05-26 00:00:00 -05:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
12
+ date: 2011-12-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
17
15
  name: nokogiri
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70096777136780 !ruby/object:Gem::Requirement
20
17
  none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
24
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
25
22
  type: :runtime
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: rspec
29
23
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70096777136780
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70096777135780 !ruby/object:Gem::Requirement
31
28
  none: false
32
- requirements:
29
+ requirements:
33
30
  - - ~>
34
- - !ruby/object:Gem::Version
31
+ - !ruby/object:Gem::Version
35
32
  version: 2.5.0
36
33
  type: :development
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
39
- name: rake
40
34
  prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70096777135780
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &70096777134760 !ruby/object:Gem::Requirement
42
39
  none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: "0"
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
47
44
  type: :development
48
- version_requirements: *id003
49
- description: "\n Sergio provides a declarative syntax for parsing unruly xml into nice pretty hashes.\n "
50
- email:
45
+ prerelease: false
46
+ version_requirements: *70096777134760
47
+ description: ! "\n Sergio provides a declarative syntax for parsing unruly xml
48
+ into nice pretty hashes.\n "
49
+ email:
51
50
  - maxjustus@gmail.com
52
51
  executables: []
53
-
54
52
  extensions: []
55
-
56
53
  extra_rdoc_files: []
57
-
58
- files:
54
+ files:
59
55
  - .gitignore
60
56
  - Gemfile
61
57
  - Gemfile.lock
@@ -73,40 +69,38 @@ files:
73
69
  - spec/support/buzz_activity_stream.xml
74
70
  - spec/support/facebook_activity_stream.xml
75
71
  - spec/support/twitter_activity_stream.xml
72
+ - spec/support/weird_unicode.xml
76
73
  - spec/unit/sergio_hash_methods_spec.rb
77
74
  - spec/unit/sergio_spec.rb
78
- has_rdoc: true
79
75
  homepage: https://github.com/maxjustus/Sergio
80
76
  licenses: []
81
-
82
77
  post_install_message:
83
78
  rdoc_options: []
84
-
85
- require_paths:
79
+ require_paths:
86
80
  - lib
87
- required_ruby_version: !ruby/object:Gem::Requirement
81
+ required_ruby_version: !ruby/object:Gem::Requirement
88
82
  none: false
89
- requirements:
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- version: "0"
93
- required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
88
  none: false
95
- requirements:
96
- - - ">="
97
- - !ruby/object:Gem::Version
98
- version: "0"
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
99
93
  requirements: []
100
-
101
94
  rubyforge_project: sergio
102
- rubygems_version: 1.6.2
95
+ rubygems_version: 1.8.11
103
96
  signing_key:
104
97
  specification_version: 3
105
98
  summary: SAXy xml to hash transformation.
106
- test_files:
99
+ test_files:
107
100
  - spec/spec_helper.rb
108
101
  - spec/support/buzz_activity_stream.xml
109
102
  - spec/support/facebook_activity_stream.xml
110
103
  - spec/support/twitter_activity_stream.xml
104
+ - spec/support/weird_unicode.xml
111
105
  - spec/unit/sergio_hash_methods_spec.rb
112
106
  - spec/unit/sergio_spec.rb