Sha256: 6cce6a8c5e8e5c74acff2d8e00ad38fa046c1e7aefcba5982102522c8304b7ab
Contents?: true
Size: 1.06 KB
Versions: 11
Compression:
Stored size: 1.06 KB
Contents
module Stellar class << Thresholds COMPONENTS = [:master_weight, :low, :medium, :high] VALID_RANGE = 0..255 def make(thresholds={}) # error if any of the needed components are not provided if COMPONENTS.any?{|c| thresholds[c].blank? } raise ArgumentError, "invalid thresholds hash, must have #{COMPONENTS.inspect} keys, had: #{thresholds.keys.inspect}" end # error if any of the needed components are not numbers 0 <= N <= 255 COMPONENTS.each do |c| good = true good &&= thresholds[c].is_a?(Integer) good &&= VALID_RANGE.include? thresholds[c] unless good raise ArgumentError, "invalid #{c.inspect}, must be number in (0..255), got #{thresholds[c].inspect}" end end thresholds.values_at(*COMPONENTS).pack("C*") end def parse(combined) master_weight, low, medium, high = combined.unpack("C*") { master_weight: master_weight, low: low, medium: medium, high: high, } end end end
Version data entries
11 entries across 11 versions & 1 rubygems