Sha256: c26b00a367c3481e479053c3d76ae70f242962d2b16205b6413101bc0611274d

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module LIRC
  module Commands
    def self.all_commands
      constants.keep_if do |x|
        const_get(x).instance_of?(Class)
      end.map(&public_method(:serialize_command_name))
    end

    def self.serialize_command_name(klass)
      klass = klass.to_s.split(":").fetch(-1)
      rest = klass[1..-1].gsub(/[A-Z]/) do |chr|
        "_#{chr}"
      end
      "#{klass[0]}#{rest.upcase}"
    end

    module Base
      def serialize
        return serialize_type unless respond_to?(:members)

        "#{serialize_type} #{serialize_args}"
      end

      private

      def serialize_type
        Commands.serialize_command_name(self.class)
      end

      def serialize_args
        members.map(&public_method(:send)).compact.join(" ")
      end
    end

    SendOnce = Struct.new(:remote, :button, :repeats) { include Base }
    SendStart = Struct.new(:remote, :button) { include Base }
    SendStop = Struct.new(:remote, :button) { include Base }
    List = Struct.new(:remote) { include Base }
    SetInputlog = Struct.new(:path) { include Base }
    DrvOption = Struct.new(:key, :value) { include Base }
    Simulate = Struct.new(:key, :data) { include Base }
    SetTransmitters = Struct.new(:transmitter, :mask) { include Base }
    Version = Class.new { include Base }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lirc-0.3.0 lib/lirc/commands.rb