Sha256: 428e7e8ad55919dbc8fd01f90095ef8d51350f82441c59659da8889fcb30f9f8

Contents?: true

Size: 752 Bytes

Versions: 4

Compression:

Stored size: 752 Bytes

Contents

# frozen_string_literal: true

module WeatherLink
  class SensorRecord < HashWrapper
    attr_reader :client

    def initialize(client, data)
      @client = client
      super(data)
    end

    def to_s
      "#<#{self.class.name} time='#{time}' (#{data.size} values)>"
    end

    def inspect
      to_s
    end

    def time
      Time.at(ts)
    end

    private

    def method_missing(symbol, *args)
      return Time.at(data[symbol.to_s]) if symbol == :ts || symbol.to_s.end_with?('_at')
      return client.convert(symbol, super) if data.include?(symbol.to_s)

      super
    end

    def respond_to_missing?(symbol, include_private = false)
      return true if symbol == :ts || symbol.to_s.end_with?('_at')

      super
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
weatherlink-0.1.3 lib/weatherlink/sensor_record.rb
weatherlink-0.1.2 lib/weatherlink/sensor_record.rb
weatherlink-0.1.1 lib/weatherlink/sensor_record.rb
weatherlink-0.1.0 lib/weatherlink/sensor_record.rb