esp-idf-lib/devtools/spec/copyright.rb

Sun, 10 Sep 2023 17:29:15 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 10 Sep 2023 17:29:15 +0200
changeset 37
50dbb626fbab
parent 1
1c9894662795
permissions
-rw-r--r--

Version 0.4.3. Attempt to fix the sunlight overflow of the APDS9930 sensor in the private part of the esp-idf-lib. Removed some error checks from functions that always return OK. Store light sensor registers in the state record and report the values in the json result string.

# frozen_string_literal: true

require_relative "person"

class Copyright
  VALID_KEYS = %w[
    author
    name
    year
  ].freeze

  def initialize(hash)
    raise ArgumentError, "expect Hash, got `#{hash.class}`" unless hash.is_a?(Hash)

    validate_keys(hash)
    @metadata = hash
  end

  attr_reader :metadata

  def validate_keys(hash)
    hash.each_key do |k|
      raise ArgumentError, "unknown key: `#{k}`. valid keys are: #{VALID_KEYS.join(' ')}" unless VALID_KEYS.include? k
    end
  end

  def author?
    metadata.key?("author")
  end

  def author
    Person.new(metadata["author"])
  end

  def name
    Person.new("name" => metadata["name"])
  end

  def name?
    metadata.key?("name")
  end

  def year
    metadata["year"]
  end

  def year?
    metadata.key?("year")
  end
end

mercurial