sax_stream 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5738222c184e824b0b1df587aa49db89b929d250
4
+ data.tar.gz: 0d334e709b9546370943ec9db6d1f7c4132b802b
5
+ SHA512:
6
+ metadata.gz: fc90bdaba07bfacd77a4eeff6110a991c354409fa6cf118061ec3e46dd90f49d91037faaef0680bb9f2f7dfb9ba6784b6bd2245dc3cc7ff68c3be8388783b053
7
+ data.tar.gz: 79f209f1e3eff0c5a19223015c96394e0d98b79d8a3608ad45f902ab48788f37a76ad61230b1beaafdde01dc6b2ecdfc85afc114e4893b2472da39e4abeace3f
data/README.markdown CHANGED
@@ -40,7 +40,7 @@ class Product
40
40
  end
41
41
  ```
42
42
 
43
- In this example, Product is a mapping class. It maps to an xml node named "product". Each "attribute" on this product object is defined using the "map" class method. The :to option uses a syntax which is similar to XPath, but not the same. Slashes seperate levels in the XML node heirarchy. If the data is in an attribute, this is designated by the @symbol. Obviously attributes must be at the end of the path, as they have no children. This product class is used to parse XML like this:
43
+ In this example, Product is a mapping class. It maps to an xml node named "product". Each "attribute" on this product object is defined using the "map" class method. The :to option uses a syntax which is similar to XPath, but not the same. Slashes seperate levels in the XML node hierarchy. If the data is in an attribute, this is designated by the @symbol. Obviously, attributes must be at the end of the path, as they have no children. This product class is used to parse XML like this:
44
44
 
45
45
  ```xml
46
46
  <?xml version="1.0" encoding="UTF-8"?>
@@ -49,7 +49,7 @@ In this example, Product is a mapping class. It maps to an xml node named "produ
49
49
  </product>
50
50
  ```
51
51
 
52
- All data written to your object from the XML will be string, unless you convert the. To specify a converter on a field mapping, use the :as option.
52
+ All data written to your object from the XML will be a string, unless you convert it. To specify a converter on a field mapping, use the :as option.
53
53
 
54
54
  ```ruby
55
55
  map :created_at, :to => '@createdAt', :as => DateTime
@@ -100,4 +100,4 @@ Author: [Craig Ambrose](http://www.craigambrose.com)
100
100
 
101
101
  Initial development sponsored by: [List Globally](http://www.listglobally.com)
102
102
 
103
- Ideas taken from lots of other great libraries, including ROXML, Happymapper, Sax Machine, and of course very reliant on Nokogiri.
103
+ Ideas taken from lots of other great libraries, including ROXML, Happymapper, Sax Machine, and of course very reliant on Nokogiri.
@@ -66,8 +66,7 @@ module SaxStream
66
66
  end
67
67
 
68
68
  def path
69
- return nil if @elements.empty?
70
- @elements.map(&:name).compact.join('/')
69
+ @elements.inject(""){|s,e| s += "#{e.name}/" unless e.name.nil?;s }.chop unless @elements.empty?
71
70
  end
72
71
 
73
72
  def content
@@ -13,13 +13,20 @@ module SaxStream
13
13
  @handler_stack.root = CombinedHandler.new(@handler_stack, mapper_handlers)
14
14
  end
15
15
 
16
- [:start_element, :end_element, :characters, :cdata_block].each do |key|
17
- code = <<-RUBY
18
- def #{key}(*params)
19
- @handler_stack.top.#{key}(*params)
20
- end
21
- RUBY
22
- module_eval(code)
16
+ def start_element(*params)
17
+ @handler_stack.top.start_element(*params)
18
+ end
19
+
20
+ def end_element(*params)
21
+ @handler_stack.top.end_element(*params)
22
+ end
23
+
24
+ def characters(*params)
25
+ @handler_stack.top.characters(*params)
26
+ end
27
+
28
+ def cdata_block(*params)
29
+ @handler_stack.top.cdata_block(*params)
23
30
  end
24
31
 
25
32
  def error(string)
@@ -94,11 +94,11 @@ module SaxStream
94
94
  end
95
95
 
96
96
  def mappings
97
- parent_class_values(:mappings, CoreExtensions::OrderedHash.new).merge(class_mappings).freeze
97
+ @mappings_incuding_inherited ||= parent_class_values(:mappings, CoreExtensions::OrderedHash.new).merge(class_mappings).freeze
98
98
  end
99
99
 
100
100
  def regex_mappings
101
- mappings.reject do |key, mapping|
101
+ @regex_mappings ||= mappings.reject do |key, mapping|
102
102
  !key.is_a?(Regexp)
103
103
  end
104
104
  end
@@ -3,7 +3,7 @@ module SaxStream
3
3
  class Decimal
4
4
  def self.parse(value)
5
5
  if value
6
- value = value.gsub(/[^\.0-9]/, '')
6
+ value = value.gsub(/[^\-\.0-9]/, '')
7
7
  return nil if value == ''
8
8
  Float(value)
9
9
  end
@@ -3,7 +3,7 @@ module SaxStream
3
3
  class Integer
4
4
  def self.parse(value)
5
5
  if value
6
- value = value.gsub(/[^\.0-9]/, '')
6
+ value = value.gsub(/[^\-\.0-9]/, '')
7
7
  return nil if value == ''
8
8
  Float(value).to_i
9
9
  end
metadata CHANGED
@@ -1,27 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sax_stream
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
5
- prerelease:
4
+ version: 1.0.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Craig Ambrose
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-05-17 00:00:00.000000000 Z
11
+ date: 2014-04-17 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: nokogiri
16
- requirement: &70150393813820 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 1.5.2
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *70150393813820
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.5.2
25
27
  description: A streaming XML parser which builds objects and passes them to a collecter
26
28
  as they are ready. Based upon Nokogiri SAX parsing functionality.
27
29
  email:
@@ -57,27 +59,26 @@ files:
57
59
  - README.markdown
58
60
  homepage: http://github.com/craigambrose/sax_stream
59
61
  licenses: []
62
+ metadata: {}
60
63
  post_install_message:
61
64
  rdoc_options: []
62
65
  require_paths:
63
66
  - lib
64
67
  required_ruby_version: !ruby/object:Gem::Requirement
65
- none: false
66
68
  requirements:
67
- - - ! '>='
69
+ - - '>='
68
70
  - !ruby/object:Gem::Version
69
71
  version: '0'
70
72
  required_rubygems_version: !ruby/object:Gem::Requirement
71
- none: false
72
73
  requirements:
73
- - - ! '>='
74
+ - - '>='
74
75
  - !ruby/object:Gem::Version
75
76
  version: '0'
76
77
  requirements: []
77
78
  rubyforge_project:
78
- rubygems_version: 1.8.6
79
+ rubygems_version: 2.0.3
79
80
  signing_key:
80
- specification_version: 3
81
+ specification_version: 4
81
82
  summary: A streaming XML parser which builds objects and passes them to a collecter
82
83
  as they are ready
83
84
  test_files: []