ruby-proto 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 02c7b90fc7cf00409cc8bc945c69956cc1098c77
4
- data.tar.gz: 0e163d827236cd730ba24a01cae947e2959ecd1b
3
+ metadata.gz: 4673b7026dc40f98d8c95a787c56cf1bd5379f61
4
+ data.tar.gz: 2becd3b52e3ee29ce0015aeeab826a8777325aba
5
5
  SHA512:
6
- metadata.gz: 940dabe1431b03923d7e6371edf66613e05af285da04e52d34db570147a6f1cdb9b7da8d065322f32c114caa2075bcb93b8ed555d5a792d51f0da4f3fd38564a
7
- data.tar.gz: 737e7a5fb6896fa04aef5bc69eb384596ca45fdd9e69fb8a2ccd03c7e6b63047b0c5d9b8e79aa565da36c4dc5c3f7bc8a4fb41cec7ca6a8202a1b3a1026dd5bf
6
+ metadata.gz: 0cdd3f388c6b12a79b5245cc52ea9750d6fe453041c6856d1dacea909ebbfcbd14cdc338333733afa5134e3aeb540e81851c1905fa3db3c15cd50857e14d4da9
7
+ data.tar.gz: 187829a9df2c99ccd12692e666d65ffdedc6e2c85e4ab2733d482bd3b33b953e9674f20dc0f1a1628390adf58c16253153ab1837d34e9956475ea374d00e2e87
@@ -1,5 +1,5 @@
1
1
  module Ruby
2
2
  module Proto
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
data/lib/ruby/proto.rb CHANGED
@@ -1,7 +1,62 @@
1
- require "ruby/proto/version"
1
+ require 'ruby/proto/version'
2
2
 
3
3
  module Ruby
4
4
  module Proto
5
- # Your code goes here...
5
+ class << self
6
+ def toProtoData(_hash, _proc)
7
+ protoData(proc, _hash)
8
+ proc
9
+ end
10
+
11
+ private
12
+ def getBasicField
13
+ @arrBasicField ||= ["int32", "uint32", "string", "bool"]
14
+ end
15
+
16
+ def convert_basic_field_value(_field, _value)
17
+ return _value if _value.is_a?(Array)
18
+ return _value if _value.is_a?(Hash)
19
+ index = getBasicField.index(_field.type.to_s)
20
+ unless index.nil?
21
+ _value = case index
22
+ when 0..1
23
+ _value.to_i
24
+ when 2
25
+ _value.to_s
26
+ when 3
27
+ _value == 1
28
+ else
29
+ _value
30
+ end
31
+ end
32
+ _value
33
+ end
34
+
35
+ def protoData(_proc, _hash)
36
+ _proc.fields.each do |_tag, _field|
37
+ ret = _hash.fetch(_field.name.to_s, nil)
38
+ next if ret.nil?
39
+ if ret.is_a?(Hash)
40
+ subProc = _field.type.new
41
+ protoData(subProc, ret)
42
+ ret = subProc
43
+ elsif ret.is_a?(Array)
44
+ arr = []
45
+ ret.each do |_hash|
46
+ subProc = nil
47
+ if (getBasicField.include?(_field.type.to_s))
48
+ subProc = convert_basic_field_value(_field, _hash)
49
+ else
50
+ subProc = _field.type.new
51
+ protoData(subProc, _hash)
52
+ end
53
+ arr.push subProc
54
+ end
55
+ ret = arr
56
+ end
57
+ _proc.send(_field.name.to_s + "=", ret)
58
+ end
59
+ end
60
+ end
6
61
  end
7
62
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-proto
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
  - Rubyer