openhab-scripting 4.12.1 → 4.13.0

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
  SHA256:
3
- metadata.gz: f6e235cb755ab3a382e6c26092492655347aeb90fb93b4449c64c7ae78b084ba
4
- data.tar.gz: 6c595a32a957415cee2e0588bc1dd044f797c9b9c678ea4c130ac37f80d72f0b
3
+ metadata.gz: 6f8fbc8b811541d42b4409776ee2debc6681bfbf17d725e68b3090a31b7ab3ae
4
+ data.tar.gz: 621ae3605cd46036106b12cf64dc6eb200d7bdcd6cbd5e10cd512bc52f98f5b0
5
5
  SHA512:
6
- metadata.gz: 7641e9056c5a0b2d4e004a585bfddf5fb4c51f4228f3df9dacea2b4af3efcb7a48ca0a38214d92a6571bf5de481dae49a7c62582f917a2226d211b8070ffeac6
7
- data.tar.gz: 7cd6598c839a75c773b92000660663f2abcee197a128b66323cdcfbd3c0ca887d813fcee0eb207e112e0e19d502919ec938e822fcf8543edcd1d481edd682bfc
6
+ metadata.gz: c73ffba5f0d95ba2cf622659b9f2bb52e1e3a033c7ef4f52f04beff29abfdea86f79f4b1f9aa08dd6bc2c9478f0adad3942866c0cb556df6fd6164d18f19f389
7
+ data.tar.gz: f4f04af30d25bd46fe5625240d218f9fa610172a03d1e26d0ac0feda4efc54a8b17a403ed0b533bf2bfef79b0eaace7eb2fac7ca9ae48c88741f4a54cce39f66
@@ -64,6 +64,32 @@ module OpenHAB
64
64
  def to_s
65
65
  "#{to_string}%"
66
66
  end
67
+
68
+ #
69
+ # Scale the value to a particular range
70
+ #
71
+ # @param range [Range] the range as a numeric
72
+ # @return [Numeric] the value as a percentage of the range
73
+ #
74
+ def scale(range) # rubocop:disable Metrics/AbcSize
75
+ unless range.is_a?(Range) && range.min.is_a?(Numeric) && range.max.is_a?(Numeric)
76
+ raise ArgumentError, 'range must be a Range of Numerics'
77
+ end
78
+
79
+ result = (to_d * (range.max - range.min) / 100) + range.min
80
+ case range.max
81
+ when Integer then result.round
82
+ when Float then result.to_f
83
+ else result
84
+ end
85
+ end
86
+
87
+ # scale the value to fit in a single byte
88
+ #
89
+ # @return [Integer] an integer in the range 0-255
90
+ def to_byte
91
+ scale(0..255)
92
+ end
67
93
  end
68
94
  end
69
95
  end
@@ -5,5 +5,5 @@
5
5
  #
6
6
  module OpenHAB
7
7
  # @return [String] Version of OpenHAB helper libraries
8
- VERSION = '4.12.1'
8
+ VERSION = '4.13.0'
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: 4.12.1
4
+ version: 4.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian O'Connell