sax_stream 1.0.8 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/sax_stream/mapper.rb +16 -1
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e83e373a7bc90e401eb641014f64d917ed014b5f
4
- data.tar.gz: 387a4de3dbe6f51007307b95ffe43d73a6ec0895
3
+ metadata.gz: 49235c762a9789fcd36ed72fc59c778ca068ec86
4
+ data.tar.gz: 0cc605f5ff26e9e778d4ff4637bd74fbd2a29a96
5
5
  SHA512:
6
- metadata.gz: ea9cc9d59e7024e2bc6710935db2cdc6d8eab4a8891a14dbdf311238d9f72bdd33b740dc553b666b7fe18e05f41b6cd8312cdda4aa147cde7df34ea55cffb3b5
7
- data.tar.gz: 88af05872978bcef1b2467cdf5dfa388e1129a3dc2e59f2e60d1c2b48d2aeb1359215257e43d6297a6ce97f38ac0b7269ed3afae8804b0710a6e6a41c026515f
6
+ metadata.gz: 561128d363d81a3596e117c85376a4589156a8b374abc8c00103d5db6ef83a4205f7c5e7d74848436edbdaefae9d82f4f51b58f5e78cbb4417fcca423452db32
7
+ data.tar.gz: f12955697cc9d6aad78890e192664c8ce7ab51302a7b6ad845f4b10d2ff5ab9f344a9959ff5d50b38c69dd169115e47cf942626be54f764736e457de1aa7dc41
@@ -39,6 +39,8 @@ module SaxStream
39
39
  # For relations, this can include a wildcard "*" as the last part of the path,
40
40
  # eg: "product/review/*". If the path is just set to "*" then this will match
41
41
  # any immediate child of the current node, which is good for polymorphic collections.
42
+ # You can also specify an array of strings to match against multiple paths, for example,
43
+ # to: ['/images/*', 'files/*', 'base_image']
42
44
  # [:as] Required, no default value.
43
45
  # Needs to be a class which includes SaxStream::Mapper, or an array of such classes.
44
46
  # Using an array of classes, even if the array only has one item, denotes that an
@@ -129,10 +131,23 @@ module SaxStream
129
131
  end
130
132
 
131
133
  def store_field_mapping(key, mapping)
132
- key = Regexp.new(key.gsub('*', '[^/]+')) if key.include?('*')
134
+ key = build_key_from_array(key)
133
135
  class_mappings[key] = mapping
134
136
  end
135
137
 
138
+ def build_key_from_array(key_array)
139
+ if key_array.is_a?(Array)
140
+ joined_key = "(#{key_array.join('|')})".gsub('*', '[^/]+')
141
+ Regexp.new(joined_key)
142
+ else
143
+ build_key_regex(key_array)
144
+ end
145
+ end
146
+
147
+ def build_key_regex(key)
148
+ key.include?('*') ? Regexp.new(key.gsub('*', '[^/]+')) : key
149
+ end
150
+
136
151
  def field_mapping(key)
137
152
  mappings[key] || regex_field_mapping(key)
138
153
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sax_stream
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Craig Ambrose