atna 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NGIyMmIwYmZiMGFhMzVlMWEwMDEyYmU2Y2Y2MWM5NzY1ODg5NmRlNQ==
4
+ ZmY1NTRhNmQwMjg2ODA0MGJmZmNkMjIzYWViM2YwZmI4YzA3MzU3Ng==
5
5
  data.tar.gz: !binary |-
6
- MDkwZDg3MGViMmY2NTg0MmM5ZWM0OTZkMzU5OTY1YzIxZTRlOTYwZQ==
6
+ OTk0ZWNhOWViNDlkOGVhZGUwNjU0OWEwNDE3MmIxYzFkMmUxYjE0OA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YmU1MmQxNTg5NWY2MDMwMTBmNWY3NDcxNmQzMmIyZDM0OTUxMWVlNjVjNjMy
10
- NmVjZTY1NmI1YjJkNmY1MjM1ZGIxMjg3MTg4MjZhMWEwYzg0OTgwYmVjMjc2
11
- MWYwOWQwZWIxOGUxZjZmOTVlNDlkZGRhYWZjZTE2OGZmNzg3YmE=
9
+ ZmRlNWQ5MmI5MzkyNGZiZGNhMTQ5ZTNhOGMxZDE4MGY4NDQxZWU2OTA4Yjg2
10
+ MmQzMTMwYjY0ZjA3YWJjZjcyM2I4ZWRmYTdjNmM3NTc3YjIxYjc2MzliZTIy
11
+ YjlkZGNiYjViNjg1NGJkNzkxYjQ5ZWE0OWU2ZTdkM2Q0OTllNjk=
12
12
  data.tar.gz: !binary |-
13
- YWNkMDcxYzg2OWQzNjBlMDZmODJlZDI0N2U0Y2RhYTc1NzFiMWIxMmExM2Jj
14
- ZWMwYzdiMTBkYmQxNjhiY2ZhNzNjZGY3ODBjZjIwYjhhM2Q2ZWZiZDFmNzg3
15
- NTNlNDEyODYxNDNiMzBhYzNkYmI4YmZjNWQ5NTQ3YWEzYjYwODE=
13
+ Nzg5YjMxOTI1MDgxOWQ5ZjU0NmQyYTNkZDU3ODU0MjNkMTg3ZDA2YTZkM2U1
14
+ M2ZlYjYxN2ZlMTEyY2VhYTcyNzZmOTE1OTI5NzZjZmM2M2ZkNmE0OWEzNjNk
15
+ YjJjOTk5NWU0NTUwYTFjNjk3MmE4MTFkNjhkNDJlZjhmNzUyODk=
@@ -21,7 +21,7 @@ module ATNA
21
21
  # "EventTypeCode" => [{ :code => "2" }, { :code => "3" }])
22
22
  # msg << AuditMessage::ActiveParticipant.new(:UserID => "user2",
23
23
  # "RoleIDCode" => [{ :code => "1" }, { :code => "2" }])
24
- # # ...
24
+ # msg << AuditMessage::ParticipantObjectIdentification.new("ParticipantObjectName" => { :__text__ => "Name" })
25
25
  module RFC3881
26
26
  class AuditMessage < ATNA::Utils::XmlBuilder::Base
27
27
  class EventIdentification < ATNA::Utils::XmlBuilder::Base
@@ -60,7 +60,7 @@ module ATNA
60
60
  "Telephone Number" => 3,
61
61
  }
62
62
 
63
- attributes :UserID, :AlternativeUserID, :UserName, :UserIsRequester
63
+ attributes :UserID, :AlternativeUserID, :UserName, :UserIsRequestor
64
64
  attributes :NetworkAccessPointID, :NetworkAccessPointTypeCode
65
65
 
66
66
  class RoleIDCode < ATNA::Utils::XmlBuilder::Base
@@ -3,6 +3,8 @@ module ATNA
3
3
  module Utils
4
4
  module XmlBuilder
5
5
  class Base
6
+ TEXT_KEY = :__text__
7
+
6
8
  def self.attributes(*names)
7
9
  self.instance_eval do
8
10
  @attribute_names ||= []
@@ -10,6 +12,10 @@ module ATNA
10
12
  @attribute_names << name.to_s.to_sym
11
13
  end
12
14
 
15
+ if @attribute_names.include?(ATNA::Utils::XmlBuilder::Base::TEXT_KEY)
16
+ raise "Duplicated attribute name for TEXT [#{ATNA::Utils::XmlBuilder::Base::TEXT_KEY.inspect}]"
17
+ end
18
+
13
19
  next @attribute_names.dup
14
20
  end
15
21
  end
@@ -27,7 +33,7 @@ module ATNA
27
33
  end
28
34
 
29
35
  def self.valid_attribute?(name)
30
- attributes.include?(name.to_s.to_sym)
36
+ attributes.include?(name.to_s.to_sym) || TEXT_KEY == name
31
37
  end
32
38
 
33
39
  def self.node_class(string = false)
@@ -72,6 +78,8 @@ module ATNA
72
78
  end
73
79
  when Hash
74
80
  add_child(element_class.new(value))
81
+ else
82
+ raise "Unknown value type [#{value.class}]"
75
83
  end
76
84
  else
77
85
  raise "Unknown key [#{key.inspect}]"
@@ -86,51 +94,54 @@ module ATNA
86
94
  return self
87
95
  end
88
96
 
89
- alias_method :add_child, :<<
90
-
91
- # Convert XML
92
- #
93
- # xml ::
94
- def to_xml(xml = nil)
95
- if xml
97
+ alias_method :add_child, :'<<'
98
+
99
+ # Convert XML
100
+ #
101
+ # xml ::
102
+ def to_xml(xml = nil)
103
+ if xml
104
+ build_xml(xml)
105
+ return
106
+ else
107
+ builder = Nokogiri::XML::Builder.new(:encoding => "UTF-8") do |xml|
96
108
  build_xml(xml)
97
- return
98
- else
99
- builder = Nokogiri::XML::Builder.new(:encoding => "UTF-8") do |xml|
100
- build_xml(xml)
101
- end
102
-
103
- return builder.doc.to_xml
104
109
  end
105
- end
106
110
 
107
- def element_name
108
- self.class.name.split("::").last.to_sym
111
+ return builder.doc.to_xml
109
112
  end
113
+ end
110
114
 
111
- def sorted_children
112
- children_order = self.class.children_order
113
- @children.sort do |a,b|
114
- children_order.index(a.class) <=> children_order.index(b.class)
115
- end
115
+ def element_name
116
+ self.class.name.split("::").last.to_sym
117
+ end
118
+
119
+ def sorted_children
120
+ children_order = self.class.children_order
121
+ @children.sort do |a,b|
122
+ children_order.index(a.class) <=> children_order.index(b.class)
116
123
  end
124
+ end
117
125
 
118
- # Build xml by Nokogiri
119
- def build_xml(xml)
120
- xml.send(element_name, attributes) do
121
- sorted_children.each do |element|
122
- element.to_xml(xml)
123
- end
126
+ # Build xml by Nokogiri
127
+ def build_xml(xml)
128
+ attrs = attributes
129
+ text = attrs.delete(ATNA::Utils::XmlBuilder::Base::TEXT_KEY)
130
+
131
+ xml.send(element_name, text, attrs) do
132
+ sorted_children.each do |element|
133
+ element.to_xml(xml)
124
134
  end
125
135
  end
126
- private :build_xml
136
+ end
137
+ private :build_xml
127
138
 
128
- # Delete nil attributes on copy
129
- def attributes
130
- @attributes.dup.delete_if { |k,v| v.nil? }
131
- end
132
- private :attributes
139
+ # Delete nil attributes on copy
140
+ def attributes
141
+ @attributes.dup.delete_if { |k,v| v.nil? }
133
142
  end
143
+ private :attributes
134
144
  end
135
145
  end
136
146
  end
147
+ end
@@ -1,3 +1,3 @@
1
1
  module Atna
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atna
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tetsuhisa MAKINO
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-13 00:00:00.000000000 Z
11
+ date: 2014-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler