openhab-scripting 3.4.1 → 3.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3dc9b053a3ac139909642f0e790a231dbd4e0b370a94836b740af22283f60315
4
- data.tar.gz: 9debccaf47bdf3d8b4c80e05d861d3e43f658f22ad569a9f60acf7a214bc0f37
3
+ metadata.gz: f309bd0e53d6ef4d8e738fb95507b79a3467e386b031a7e087c15502c20442cf
4
+ data.tar.gz: 0fbf71682ac4809b5d804f47ff3e847f8632d91a2749514c04abb6e7b5e02713
5
5
  SHA512:
6
- metadata.gz: f04e70a4126f41f204b803617e757d66fe8e03f50543cc0a7a5c6c046b3567178f32d6cc6b97fbd9f0b0ca8b90c8c1fceb75b855bfe5565d4b8b7c8732e2efb8
7
- data.tar.gz: 5b2092565032d2431b488250d6dc442178ecab80642f86495f56f2f199f5b05cae2f48a78b53dea118043f96c174811a0705af5596b26c9b784d315cd0bb720d
6
+ metadata.gz: 7b323582ae4bb7e8e5d5501353f0021437fa53f4170e098f51d518f30103d6a4241474678f80d1330d1c6257de354e58633ad16ea3e5e928315a2235aba51389
7
+ data.tar.gz: 56ea9c5ec2b80d16c4f9ccdd08fbab04a45aee6460947de4df219c800e2120fa6f169290886984c25b942408ebc62c13913f03bd9a7e54aa52468e5b7e308c72
@@ -30,7 +30,7 @@ module OpenHAB
30
30
 
31
31
  def initialize(metadata: nil, key: nil, value: nil, config: nil)
32
32
  @metadata = metadata || Metadata.new(key || MetadataKey.new('', ''), value&.to_s, config)
33
- super(@metadata&.configuration)
33
+ super(to_ruby(@metadata&.configuration))
34
34
  end
35
35
 
36
36
  #
@@ -85,6 +85,44 @@ module OpenHAB
85
85
  def to_a
86
86
  [@metadata&.value, @metadata&.configuration || {}]
87
87
  end
88
+
89
+ private
90
+
91
+ #
92
+ # Recursively convert the supplied Hash object into a Ruby Hash and recreate the keys and values
93
+ #
94
+ # @param [Hash] Hash to convert
95
+ #
96
+ # @return [Hash] The converted hash
97
+ #
98
+ def to_ruby_hash(hash)
99
+ return unless hash.respond_to? :each_with_object
100
+
101
+ hash.each_with_object({}) { |(key, value), ruby_hash| ruby_hash[to_ruby(key)] = to_ruby(value) }
102
+ end
103
+
104
+ #
105
+ # Recursively convert the supplied array to a Ruby array and recreate all String values
106
+ #
107
+ # @param [Object] array to convert
108
+ #
109
+ # @return [Array] The converted array
110
+ #
111
+ def to_ruby_array(array)
112
+ return unless array.respond_to? :each_with_object
113
+
114
+ array.each_with_object([]) { |value, ruby_array| ruby_array << to_ruby(value) }
115
+ end
116
+
117
+ # Convert the given object to Ruby equivalent
118
+ def to_ruby(value)
119
+ case value
120
+ when Hash, Java::JavaUtil::Map then to_ruby_hash(value)
121
+ when Array, Java::JavaUtil::List then to_ruby_array(value)
122
+ when String then String.new(value)
123
+ else value
124
+ end
125
+ end
88
126
  end
89
127
 
90
128
  #
@@ -5,5 +5,5 @@
5
5
  #
6
6
  module OpenHAB
7
7
  # @return [String] Version of OpenHAB helper libraries
8
- VERSION = '3.4.1'
8
+ VERSION = '3.4.2'
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openhab-scripting
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.1
4
+ version: 3.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian O'Connell