contmx 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- metadata +3 -5
- data/lib/contmx.rb +0 -5
- data/lib/writerxml.rb +0 -256
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0515ebb466b809651b43783b9ab53b53ba0b2354
|
4
|
+
data.tar.gz: 886ff28708942cb661c2778f9785bb4bbd9e6183
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a1ee2715d322798e7ff8a9d637c3b43f402f53736c016addb40cd18626c2b75e55caee5a1fa523496aab2d33d7b9eebd7c89576023a1ba8a75671427f61fc30
|
7
|
+
data.tar.gz: 390b7d0c16eb9ebc88b4a4cce8c9b2927f7057c6f66d6b407c41915d534721e6ef92a63fe15476bb74cec31c3b24e06041c70b63ca8c20c65b8cf2377a0ccf8c
|
metadata
CHANGED
@@ -1,23 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contmx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cesar Castillo Moreno
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: XML de contabilidad de Mexico
|
14
14
|
email: cesar.cast.more@gmail.com
|
15
15
|
executables: []
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
|
-
files:
|
19
|
-
- lib/contmx.rb
|
20
|
-
- lib/writerxml.rb
|
18
|
+
files: []
|
21
19
|
homepage: https://github.com/cesarcastmore/contmx
|
22
20
|
licenses:
|
23
21
|
- MIT
|
data/lib/contmx.rb
DELETED
data/lib/writerxml.rb
DELETED
@@ -1,256 +0,0 @@
|
|
1
|
-
class WriterXML
|
2
|
-
attr_reader :attributes, :elements, :schemaLocation, :targetNamespace, :objects;
|
3
|
-
|
4
|
-
def initialize(hash)
|
5
|
-
|
6
|
-
end
|
7
|
-
|
8
|
-
=begin
|
9
|
-
Metodo que lee el hash o el arreglo y asigna cada uno de los valores a sus respetivas
|
10
|
-
variables
|
11
|
-
@param [Hash] [Array]
|
12
|
-
=end
|
13
|
-
def from_hash(para)
|
14
|
-
|
15
|
-
if !para.nil?
|
16
|
-
@attributes = [] if @attributes.nil?
|
17
|
-
@sequence = [] if @sequence.nil?
|
18
|
-
|
19
|
-
hash_objects = from_hash_to_array_objects(para)
|
20
|
-
set_atr_object_from_hash(para,hash_objects)
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
=begin
|
27
|
-
Metodo que leera cada uno de los atributos y hara un hash de toda la clase
|
28
|
-
@return [Hash] crear un hash leyendo las variables
|
29
|
-
=end
|
30
|
-
def to_hash
|
31
|
-
hash = {}
|
32
|
-
if !@attributes.nil?
|
33
|
-
return hash
|
34
|
-
end
|
35
|
-
@attributes.each { |attr|
|
36
|
-
downcaseAttr = attr.downcase
|
37
|
-
if instance_attribute_defined?(downcaseAttr)
|
38
|
-
hash[attr.to_sym] = get(downcaseAttr)
|
39
|
-
end
|
40
|
-
}
|
41
|
-
return hash;
|
42
|
-
end
|
43
|
-
|
44
|
-
=begin
|
45
|
-
Metodo que obtiene el objecto o el atributos de la clase
|
46
|
-
@return [Object] regresa un objecto dependiendo del atributos o nodos
|
47
|
-
=end
|
48
|
-
|
49
|
-
def get(key)
|
50
|
-
case key
|
51
|
-
when Symbol
|
52
|
-
return instance_variable_get("@#{key}")
|
53
|
-
when String
|
54
|
-
return instance_variable_get("@#{key}")
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
=begin
|
60
|
-
Asignara una instancia basandose en el symbolo que se indica en el parametro
|
61
|
-
@param [Symbol, String] , [Object]
|
62
|
-
=end
|
63
|
-
def set(key, value)
|
64
|
-
case key
|
65
|
-
when Symbol
|
66
|
-
return instance_variable_set("@#{key}", value)
|
67
|
-
when String
|
68
|
-
return instance_variable_set("@#{key}", value)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def [](key)
|
73
|
-
return get(key)
|
74
|
-
end
|
75
|
-
|
76
|
-
=begin
|
77
|
-
Metodo que revise la existencia del atributos dentro de la clase
|
78
|
-
@param [Sysbol, String]
|
79
|
-
@return [Boolean]
|
80
|
-
=end
|
81
|
-
def instance_attribute_defined?(key)
|
82
|
-
case key
|
83
|
-
when Symbol
|
84
|
-
return instance_variable_defined?("@#{key}")
|
85
|
-
when String
|
86
|
-
return instance_variable_defined?("@#{key}")
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
=begin
|
91
|
-
Escribira en el objecto del parametro y revisara si el objecto es raiz o
|
92
|
-
es un nodo de una sequencia, si es la raiz agregara un prefijo si esta especificado
|
93
|
-
en las variables de instancia
|
94
|
-
@param [Nokogiri::XML::Builder ]
|
95
|
-
=end
|
96
|
-
|
97
|
-
def writeXML(xml)
|
98
|
-
if @targetNamespace.nil?
|
99
|
-
xml.send(self.class.to_s){
|
100
|
-
write_attributes_elements(xml)
|
101
|
-
}
|
102
|
-
else
|
103
|
-
prefix = "#{@targetNamespace[:prefix]}"
|
104
|
-
namespace = "#{@targetNamespace[:namespace]}"
|
105
|
-
xml.send(self.class.to_s){
|
106
|
-
ins = xml.parent.add_namespace_definition(prefix, namespace)
|
107
|
-
xml.parent.namespace = ins
|
108
|
-
write_attributes_elements(xml)
|
109
|
-
}
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
#@private
|
114
|
-
private
|
115
|
-
=begin
|
116
|
-
Este metodo coloca todos los atributos y ademas tambien coloca los namespace en
|
117
|
-
un hash, es usando para poder usar el metodo de writerXML
|
118
|
-
@return [Hash]
|
119
|
-
=end
|
120
|
-
def attribites_to_hash
|
121
|
-
hash = {}
|
122
|
-
|
123
|
-
if !@targetNamespace.nil?
|
124
|
-
prefix = "#{@targetNamespace[:prefix]}"
|
125
|
-
namespace = "#{@targetNamespace[:namespace]}"
|
126
|
-
hash[prefix] = namespace;
|
127
|
-
end
|
128
|
-
|
129
|
-
if !@attributes.nil?
|
130
|
-
@attributes.each { |attr|
|
131
|
-
downcaseAttr = attr.downcase
|
132
|
-
if instance_attribute_defined?(downcaseAttr)
|
133
|
-
hash[attr.to_sym] = get(downcaseAttr)
|
134
|
-
end
|
135
|
-
}
|
136
|
-
end
|
137
|
-
|
138
|
-
if !@schemaLocation.nil?
|
139
|
-
hash["xmlns:xsi"] = "http://www.w3.org/2001/XMLSchema-instance"
|
140
|
-
hash["xsi:schemaLocation"] = "#{@schemaLocation}"
|
141
|
-
end
|
142
|
-
return hash;
|
143
|
-
end
|
144
|
-
=begin
|
145
|
-
Metodo que sirve para escribir los atributos y los nodos en el Nokogiri::XML::Builder
|
146
|
-
@param [Nokogiri::XML::Builder ] parametro que se escribira
|
147
|
-
=end
|
148
|
-
|
149
|
-
def write_attributes_elements(xml)
|
150
|
-
attributes = attribites_to_hash
|
151
|
-
if !attributes.nil?
|
152
|
-
attributes.each { |key, value|
|
153
|
-
xml.parent.set_attribute(key,value)
|
154
|
-
}
|
155
|
-
end
|
156
|
-
array_elements = elements_to_array_objects
|
157
|
-
if !array_elements.empty?
|
158
|
-
array_elements.each { |object|
|
159
|
-
object.writeXML(xml)
|
160
|
-
}
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
=begin
|
165
|
-
Metodo para buscar los objecto de la secuencia y instanciarlos en un arreglo donde
|
166
|
-
seran utilizado para el metodo writeXML
|
167
|
-
@return [Array]
|
168
|
-
=end
|
169
|
-
|
170
|
-
def sequence_to_array_objects
|
171
|
-
array = []
|
172
|
-
if !@sequence.empty?
|
173
|
-
@sequence.each { |element|
|
174
|
-
downcaseElement = element.downcase
|
175
|
-
if instance_attribute_defined?(downcaseElement)
|
176
|
-
object = get(downcaseElement)
|
177
|
-
if object.kind_of?(Array)
|
178
|
-
return object
|
179
|
-
else
|
180
|
-
array << object
|
181
|
-
end
|
182
|
-
end
|
183
|
-
}
|
184
|
-
else
|
185
|
-
if !@objects.nil?
|
186
|
-
@objects.each { |o|
|
187
|
-
array << o
|
188
|
-
}
|
189
|
-
end
|
190
|
-
end
|
191
|
-
return array;
|
192
|
-
end
|
193
|
-
=begin
|
194
|
-
Revisa la secuencia, si la secuencia no esta en vacio reguesa un hash con el nombre
|
195
|
-
de las clases, en cambio si esta vacio, asigna variables de objecto a la clase raiz
|
196
|
-
@param [Hash] [Array]
|
197
|
-
@return [Hash] regresa el nombre de clases con key de la clase en minusculas
|
198
|
-
=end
|
199
|
-
|
200
|
-
|
201
|
-
def from_hash_to_array_objects(para)
|
202
|
-
hash_objects = {}
|
203
|
-
if !@sequence.empty?
|
204
|
-
@sequence.each { |o|
|
205
|
-
hash_objects[o.downcase.to_sym] = o
|
206
|
-
}
|
207
|
-
else
|
208
|
-
if para.kind_of?(Array)
|
209
|
-
@objects= Array.new
|
210
|
-
array_hashing = para
|
211
|
-
array_hashing.each { | l |
|
212
|
-
l.each { |k, v|
|
213
|
-
object = Object.const_get(k.to_s).new(v)
|
214
|
-
@objects << object
|
215
|
-
}
|
216
|
-
}
|
217
|
-
end
|
218
|
-
end
|
219
|
-
return hash_objects
|
220
|
-
end
|
221
|
-
=begin
|
222
|
-
Metodo que mapea todo el hash a un asignacion en la clase, se basa los atributos y sequence
|
223
|
-
inicializada en la para de arriba
|
224
|
-
@param [Hash] es hash es para mapear todos los atributos con sus asignaciones
|
225
|
-
@param [Array] es un arreglo con el nombre de los objectos, es como se llaman los objectos
|
226
|
-
ya que se inicializara y se asignaran
|
227
|
-
=end
|
228
|
-
def set_atr_object_from_hash(para, hash_objects)
|
229
|
-
|
230
|
-
attributes_downcase =@attributes.map(&:downcase)
|
231
|
-
elements_downcase =@sequence.map(&:downcase)
|
232
|
-
|
233
|
-
if para.kind_of? Hash
|
234
|
-
para.each { |key, value|
|
235
|
-
keyDowncase = key.downcase
|
236
|
-
if(attributes_downcase.include?( keyDowncase.to_s))
|
237
|
-
set( keyDowncase, value)
|
238
|
-
elsif (elements_downcase.include?(keyDowncase.to_s))
|
239
|
-
if(value.kind_of?(Hash))
|
240
|
-
object = Object.const_get(hash_objects[keyDowncase.to_sym]).new(value)
|
241
|
-
set( keyDowncase, object)
|
242
|
-
elsif (value.kind_of?(Array))
|
243
|
-
objects= Array.new
|
244
|
-
value.each { |e|
|
245
|
-
object = Object.const_get(hash_objects[keyDowncase.to_sym]).new(value)
|
246
|
-
@objects << object
|
247
|
-
}
|
248
|
-
set( keyDowncase, objects)
|
249
|
-
end
|
250
|
-
end
|
251
|
-
}
|
252
|
-
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
end
|