#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,7 +1,13 @@
|
||||||
|
Description
|
||||||
|
===========
|
||||||
|
|
||||||
lircr (pronounced 'lurker') is a LIRC client library for Ruby. It's simple,
|
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
|
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.
|
grow more hair on your index finger or thumb.
|
||||||
|
|
||||||
|
Usage
|
||||||
|
=====
|
||||||
|
|
||||||
require 'lirc'
|
require 'lirc'
|
||||||
lirc = LIRC::Client.new
|
lirc = LIRC::Client.new
|
||||||
event = lirc.next
|
event = lirc.next
|
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
|
end
|
||||||
|
|
22
lib/lirc.rb
22
lib/lirc.rb
|
@ -2,25 +2,37 @@ require 'socket'
|
||||||
|
|
||||||
module LIRC
|
module LIRC
|
||||||
class Client
|
class Client
|
||||||
def initialize(dev="/dev/lircd")
|
def initializer dev = nil
|
||||||
@sock = UNIXSocket.open(dev)
|
dev ||= "/dev/lircd"
|
||||||
|
@sock = UNIXSocket.open dev
|
||||||
end
|
end
|
||||||
|
|
||||||
def next
|
def next
|
||||||
Event.new(@sock.readline)
|
Event.new @sock.readline
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def each_event
|
||||||
|
return Enumerator.new( self, :each_event) unless block_given?
|
||||||
|
loop { yield self.next }
|
||||||
end
|
end
|
||||||
|
alias each each_event
|
||||||
|
end
|
||||||
|
|
||||||
class Event
|
class Event
|
||||||
attr_reader :code, :repeat, :name, :remote
|
attr_reader :code, :repeat, :name, :remote
|
||||||
def initialize(str)
|
|
||||||
|
def initialize str
|
||||||
code, repeat, @name, @remote = str.split(' ', 4)
|
code, repeat, @name, @remote = str.split(' ', 4)
|
||||||
@code = code.hex
|
@code = code.hex
|
||||||
@repeat = repeat.hex
|
@repeat = repeat.hex
|
||||||
end
|
end
|
||||||
|
|
||||||
def repeat?
|
def repeat?
|
||||||
@repeat > 0
|
@repeat > 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
sprintf("%016x %02x %s %s", @code, @repeat, @name, @remote)
|
"%016x %02x %s %s" % [@code, @repeat, @name, @remote]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue