happymapper 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -97,9 +97,11 @@ module HappyMapper
97
97
  namespace = @namespace || (node.namespaces && node.namespaces.default)
98
98
  namespace = "#{DEFAULT_NS}:#{namespace}" if namespace
99
99
 
100
- xpath = root ? '/' : './/'
101
- xpath += "#{DEFAULT_NS}:" if namespace
102
- xpath += tag_name
100
+ unless xpath = options[:xpath]
101
+ xpath = root ? '/' : './/'
102
+ xpath += "#{DEFAULT_NS}:" if namespace
103
+ xpath += tag_name
104
+ end
103
105
 
104
106
  nodes = node.find(xpath, Array(namespace))
105
107
  collection = nodes.collect do |n|
@@ -1,3 +1,3 @@
1
1
  module HappyMapper
2
- Version = '0.4.0'
2
+ Version = '0.4.1'
3
3
  end
@@ -0,0 +1,29 @@
1
+ <tsResponse requestOp="getUserMessages" resultCode="0" timestamp="1329416249820"
2
+ timetaken="475">
3
+ <msg msgID="123456">
4
+ <msgID>123456</msgID>
5
+ <conID>789012</conID>
6
+ <symbol>2012.PIGS.FLY</symbol>
7
+ <readFlag>false</readFlag>
8
+ <type>T</type>
9
+ <msg>345678901</msg>
10
+ <price>13.0</price>
11
+ <quantity>100</quantity>
12
+ <side>B</side>
13
+ <timestamp>1329415852000</timestamp>
14
+ </msg>
15
+ <msg msgID="123460">
16
+ <msgID>123460</msgID>
17
+ <conID>789013</conID>
18
+ <symbol>2012.SNOWBALL.INFERNO.MELT</symbol>
19
+ <readFlag>false</readFlag>
20
+ <type>T</type>
21
+ <msg>345678933</msg>
22
+ <price>13.0</price>
23
+ <quantity>100</quantity>
24
+ <side>S</side>
25
+ <timestamp>1329415873000</timestamp>
26
+ </msg>
27
+ <faildesc>Ok</faildesc>
28
+ <sessionData>10R3M1p5um0010r5174m37c0n53C737uR401p151C1N931175300031U5m0073mp0r1Nc1010UN7u71480R3370010R3m49n44119u4U73N1M40M1n1MV3n14M9U15n057Ru03X3Rc174710Nu114Mc01480r15n151u74119U1P3x34C0mm000C0n539u470u154u731ruR30010r1Nr3PR3h3n03R171Nv01up7473v31173553C111Um0010R33ufU9147nu114P4R147Ur3XC3P73uR51n70CC43C47CuP104747n0nPR0103N75un71ncu1p49U10fF1C140353rUn7m011174N1M103571480Rum</sessionData>
29
+ </tsResponse>
@@ -350,6 +350,19 @@ describe HappyMapper do
350
350
  # tree.people.first.id.should == 'KWQS-BBQ'
351
351
  end
352
352
 
353
+ it "should support :xpath option" do
354
+ message_box = Intrade::Messages.parse(fixture_file('intrade.xml'))
355
+ message_box.timestamp.should == Time.at(1329416249)
356
+ message_box.error_message.should == "Ok"
357
+
358
+ # default xpath would default to './/msg', which would include
359
+ # nested nodes which are also named "msg", so xpath is
360
+ # explicitly supplied as option :xpath => './msg'
361
+ message_box.messages.should have(2).messages
362
+ message_box.messages[0].message_id.should == 123456
363
+ message_box.messages[1].message_id.should == 123460
364
+ end
365
+
353
366
  describe 'nested elements with namespaces' do
354
367
  module Namespaces
355
368
  class Info
@@ -299,4 +299,39 @@ module Backpack
299
299
 
300
300
  content :body
301
301
  end
302
- end
302
+ end
303
+
304
+ module Intrade
305
+ class EpochMillis
306
+ def self.parse(millis); Time.at(millis.to_i / 1000); end
307
+ end
308
+
309
+ class Message
310
+ include HappyMapper
311
+
312
+ tag 'msg'
313
+ attribute :message_id, Integer, :tag => 'msgID'
314
+ element :contract_id, Integer, :tag => 'conID'
315
+ element :symbol, String, :tag => 'symbol'
316
+ element :is_read, Boolean, :tag => 'readFlag'
317
+ element :type, String, :tag => 'type'
318
+ element :text, String, :tag => 'msg'
319
+ element :price, Float, :tag => 'price'
320
+ element :quantity, Integer, :tag => 'quantity'
321
+ element :side, String, :tag => 'side'
322
+ element :timestamp, EpochMillis, :tag => 'timestamp', :parser => :parse
323
+ end
324
+
325
+ class Messages
326
+ include HappyMapper
327
+
328
+ tag 'tsResponse'
329
+ attribute :operation, String, :tag => 'requestOp'
330
+ attribute :timestamp, EpochMillis, :tag => 'timestamp', :parser => :parse
331
+ attribute :result_code, Integer, :tag => 'resultCode'
332
+ element :error_message, String, :tag => 'faildesc'
333
+ element :session_key, String, :tag => 'sessionData'
334
+ has_many :messages, Message, :tag => 'msg', :xpath => './msg'
335
+ end
336
+ end
337
+
metadata CHANGED
@@ -1,47 +1,39 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: happymapper
3
- version: !ruby/object:Gem::Version
4
- hash: 15
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.1
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 4
9
- - 0
10
- version: 0.4.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - John Nunemaker
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-09-26 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2013-09-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: libxml-ruby
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.0'
21
22
  type: :runtime
22
23
  prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
24
25
  none: false
25
- requirements:
26
+ requirements:
26
27
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 2
31
- - 0
32
- version: "2.0"
33
- version_requirements: *id001
34
- name: libxml-ruby
28
+ - !ruby/object:Gem::Version
29
+ version: '2.0'
35
30
  description:
36
- email:
31
+ email:
37
32
  - nunemaker@gmail.com
38
33
  executables: []
39
-
40
34
  extensions: []
41
-
42
35
  extra_rdoc_files: []
43
-
44
- files:
36
+ files:
45
37
  - examples/amazon.rb
46
38
  - examples/current_weather.rb
47
39
  - examples/dashed_elements.rb
@@ -58,6 +50,7 @@ files:
58
50
  - spec/fixtures/commit.xml
59
51
  - spec/fixtures/current_weather.xml
60
52
  - spec/fixtures/family_tree.xml
53
+ - spec/fixtures/intrade.xml
61
54
  - spec/fixtures/multi_street_address.xml
62
55
  - spec/fixtures/multiple_namespaces.xml
63
56
  - spec/fixtures/nested_namespaces.xml
@@ -83,36 +76,32 @@ files:
83
76
  - README.rdoc
84
77
  homepage: http://happymapper.rubyforge.org
85
78
  licenses: []
86
-
87
79
  post_install_message:
88
80
  rdoc_options: []
89
-
90
- require_paths:
81
+ require_paths:
91
82
  - lib
92
- required_ruby_version: !ruby/object:Gem::Requirement
83
+ required_ruby_version: !ruby/object:Gem::Requirement
93
84
  none: false
94
- requirements:
95
- - - ">="
96
- - !ruby/object:Gem::Version
97
- hash: 3
98
- segments:
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ segments:
99
90
  - 0
100
- version: "0"
101
- required_rubygems_version: !ruby/object:Gem::Requirement
91
+ hash: -3590435398206402919
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
93
  none: false
103
- requirements:
104
- - - ">="
105
- - !ruby/object:Gem::Version
106
- hash: 3
107
- segments:
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ segments:
108
99
  - 0
109
- version: "0"
100
+ hash: -3590435398206402919
110
101
  requirements: []
111
-
112
102
  rubyforge_project: happymapper
113
- rubygems_version: 1.8.9
103
+ rubygems_version: 1.8.23
114
104
  signing_key:
115
105
  specification_version: 3
116
106
  summary: object to xml mapping library
117
107
  test_files: []
118
-