#each added, Rakefile modified for gems, README -> README.md
This commit is contained in:
parent
911e513d44
commit
42ac14e09d
4 changed files with 103 additions and 1583 deletions
|
@ -1,11 +1,17 @@
|
|||
Description
|
||||
===========
|
||||
|
||||
lircr (pronounced 'lurker') is a LIRC client library for Ruby. It's simple,
|
||||
it's easy, it's fun. If you got LIRC, get lircr. I am not responsible if you
|
||||
grow more hair on your index finger or thumb.
|
||||
|
||||
require 'lirc'
|
||||
lirc = LIRC::Client.new
|
||||
event = lirc.next
|
||||
p event
|
||||
if event.name == "play"
|
||||
system "xmms", "/av/music/3.mod"
|
||||
end
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
require 'lirc'
|
||||
lirc = LIRC::Client.new
|
||||
event = lirc.next
|
||||
p event
|
||||
if event.name == "play"
|
||||
system "xmms", "/av/music/3.mod"
|
||||
end
|
57
Rakefile
57
Rakefile
|
@ -1,4 +1,57 @@
|
|||
require 'rake/testtask'
|
||||
require 'rubygems'
|
||||
require 'rake'
|
||||
|
||||
Rake::TestTask.new do |t|
|
||||
begin
|
||||
require 'jeweler'
|
||||
Jeweler::Tasks.new do |gem|
|
||||
gem.name = "lircr"
|
||||
gem.summary = %Q{LIRC client for Ruby}
|
||||
gem.description = %Q{}
|
||||
gem.email = "Denis.Knauf@gmail.com"
|
||||
gem.homepage = "http://github.com/DenisKnauf/logan"
|
||||
gem.authors = ["Denis Knauf", "Hans Fugal"]
|
||||
gem.files = %w[AUTHORS README.md VERSION lib/**/*.rb test/**/*.rb]
|
||||
gem.require_paths = %w[test lib]
|
||||
end
|
||||
Jeweler::GemcutterTasks.new
|
||||
rescue LoadError
|
||||
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
||||
end
|
||||
|
||||
require 'rake/testtask'
|
||||
Rake::TestTask.new(:test) do |test|
|
||||
test.libs << 'lib' << 'test' << 'ext'
|
||||
test.pattern = 'test/**/*_test.rb'
|
||||
test.verbose = true
|
||||
end
|
||||
|
||||
begin
|
||||
require 'rcov/rcovtask'
|
||||
Rcov::RcovTask.new do |test|
|
||||
test.libs << 'test'
|
||||
test.pattern = 'test/**/*_test.rb'
|
||||
test.verbose = true
|
||||
end
|
||||
rescue LoadError
|
||||
task :rcov do
|
||||
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
||||
end
|
||||
end
|
||||
|
||||
task :test => :check_dependencies
|
||||
|
||||
task :default => :test
|
||||
|
||||
require 'rake/rdoctask'
|
||||
Rake::RDocTask.new do |rdoc|
|
||||
if File.exist?('VERSION')
|
||||
version = File.read('VERSION')
|
||||
else
|
||||
version = ""
|
||||
end
|
||||
|
||||
rdoc.rdoc_dir = 'rdoc'
|
||||
rdoc.title = "sbdb #{version}"
|
||||
rdoc.rdoc_files.include('README*')
|
||||
rdoc.rdoc_files.include('lib/**/*.rb')
|
||||
end
|
||||
|
|
56
lib/lirc.rb
56
lib/lirc.rb
|
@ -1,26 +1,38 @@
|
|||
require 'socket'
|
||||
|
||||
module LIRC
|
||||
class Client
|
||||
def initialize(dev="/dev/lircd")
|
||||
@sock = UNIXSocket.open(dev)
|
||||
end
|
||||
def next
|
||||
Event.new(@sock.readline)
|
||||
end
|
||||
end
|
||||
class Event
|
||||
attr_reader :code, :repeat, :name, :remote
|
||||
def initialize(str)
|
||||
code, repeat, @name, @remote = str.split(' ', 4)
|
||||
@code = code.hex
|
||||
@repeat = repeat.hex
|
||||
end
|
||||
def repeat?
|
||||
@repeat > 0
|
||||
end
|
||||
def to_s
|
||||
sprintf("%016x %02x %s %s", @code, @repeat, @name, @remote)
|
||||
end
|
||||
end
|
||||
class Client
|
||||
def initializer dev = nil
|
||||
dev ||= "/dev/lircd"
|
||||
@sock = UNIXSocket.open dev
|
||||
end
|
||||
|
||||
def next
|
||||
Event.new @sock.readline
|
||||
end
|
||||
|
||||
def each_event
|
||||
return Enumerator.new( self, :each_event) unless block_given?
|
||||
loop { yield self.next }
|
||||
end
|
||||
alias each each_event
|
||||
end
|
||||
|
||||
class Event
|
||||
attr_reader :code, :repeat, :name, :remote
|
||||
|
||||
def initialize str
|
||||
code, repeat, @name, @remote = str.split(' ', 4)
|
||||
@code = code.hex
|
||||
@repeat = repeat.hex
|
||||
end
|
||||
|
||||
def repeat?
|
||||
@repeat > 0
|
||||
end
|
||||
|
||||
def to_s
|
||||
"%016x %02x %s %s" % [@code, @repeat, @name, @remote]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue