lab5 0.0.2 → 0.0.3

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/lab5.rb +27 -1
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b07654a7d9c8825bc7cdddea42bc4c6fe11b98e
4
- data.tar.gz: 5705107c7f2b5f64da1f369d5342c9c678b811a6
3
+ metadata.gz: 136e37999c33b5cadfff5d2c18e6008bcd34b29b
4
+ data.tar.gz: 64c1834a7c8e73f4685ff6a8ad34acd5a920767d
5
5
  SHA512:
6
- metadata.gz: eef3a25e21879ca5cd16958b976f7642341aad135172464954988ca16491ff66112f751a7c089c7f70a7bb4804d10ae8cb34235e48a986075d18601d3f2e0576
7
- data.tar.gz: 00cc8b9f059ea44bc4a31f571db6faeda564ae4ff907c78e1080c01d525f698b681d1ee6893714c67fe69d6be1e3022913795e9a6762a4597af2c83c18340cd9
6
+ metadata.gz: 91e1a7558a2997522fd79fb1dc756324979a45e348cff83a775e537f11da4a5b0a09fa24a4448ee617964b90bce3e7ca351c31c28d6f09c9e48e831774755268
7
+ data.tar.gz: 93d19eaa2855b56c1c0310733adb94828c63c7ea8bf57dd8b3c0694ad9760bc284dfae027248d51acaf1078886162cadb2b986a8ca2708c6a81d1cb5eb608bdd
data/lib/lab5.rb CHANGED
@@ -2,10 +2,36 @@ require 'ox'
2
2
 
3
3
  class XmlSerializer
4
4
  def self.xml_ser(array)
5
- Ox.dump(array)
5
+ Ox.dump(XmlSerializer.object_to_hash(array))
6
6
  end
7
7
 
8
8
  def self.yaml_deser(xml)
9
9
  Ox.parse(xml)
10
10
  end
11
+
12
+ private
13
+
14
+ def self.object_to_hash(object)
15
+ variable_names = object.instance_variables
16
+ variables = {}
17
+
18
+ variable_names.each do |name|
19
+ variables[name] = object.instance_variable_get(name)
20
+ end
21
+
22
+ {
23
+ class: object.class.name,
24
+ instance_variables: variables
25
+ }
26
+ end
27
+
28
+ def self.hash_to_object(hash)
29
+ object = hash['class'].constantize.new
30
+
31
+ hash['instance_variables'].each do |name, value|
32
+ object.instance_variable_set(name, value)
33
+ end
34
+
35
+ object
36
+ end
11
37
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lab5
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tatiana Karpesh