diff --git a/.ruby-gemset b/.ruby-gemset
new file mode 100644
index 0000000..5328a1a
--- /dev/null
+++ b/.ruby-gemset
@@ -0,0 +1 @@
+blink1-devel
diff --git a/.rvmrc b/.rvmrc
deleted file mode 100644
index 55b05a2..0000000
--- a/.rvmrc
+++ /dev/null
@@ -1 +0,0 @@
-rvm gemset use blink1-devel --create
diff --git a/.travis.yml b/.travis.yml
index 4f21a80..c71f59b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,8 +1,9 @@
language: ruby
-env: CODECLIMATE_REPO_TOKEN=ea524e4acf0abd2a5d396cc239710de238314e5bfe3af472baca56a88f7b7ec1
+env: CODECLIMATE_REPO_TOKEN=ea524e4acf0abd2a5d396cc239710de238314e5bfe3af472baca56a88f7b7ec1 SPEC_OPTS='--format documentation'
rvm:
- "1.9.3"
- - rbx-19mode
+ - "2.0.0"
+ - "2.1.0"
before_install:
- sudo apt-get install -qq gcc-avr avr-libc
- sudo apt-get install -qq libusb-1.0-0-dev
diff --git a/Gemfile b/Gemfile
index 606a707..e7c4f3d 100644
--- a/Gemfile
+++ b/Gemfile
@@ -3,5 +3,5 @@ source "http://rubygems.org"
gemspec
if RUBY_VERSION >= '1.9.3'
- gem "codeclimate-test-reporter", :group => :test, :require => nil
+ gem "codeclimate-test-reporter", group: :test, require: nil
end
diff --git a/Rakefile b/Rakefile
index 7a6a767..44d6465 100644
--- a/Rakefile
+++ b/Rakefile
@@ -2,8 +2,8 @@ require 'bundler/gem_tasks'
require 'rdoc/task'
require 'rspec/core/rake_task'
-task :default => :spec
-task :spec => :build
+task default: :spec
+task spec: :build
task :build do
Dir.chdir('ext/blink1') do
@@ -18,12 +18,10 @@ end
RSpec::Core::RakeTask.new
RDoc::Task.new do |rdoc|
-
rdoc.rdoc_files.include("README.rdoc", "lib/**/*.rb", "ext/blink1/blink1.c")
rdoc.generator = 'bootstrap'
rdoc.main = "README.rdoc"
rdoc.rdoc_dir = 'html'
rdoc.title = 'rb-blink1'
rdoc.options << '--line-numbers'
-
end
diff --git a/lib/blink1.rb b/lib/blink1.rb
index 00cb966..718f5b6 100644
--- a/lib/blink1.rb
+++ b/lib/blink1.rb
@@ -15,18 +15,19 @@ class Blink1
# new ( {Fixnum} id )
# new ( {Boolean} auto_open )
# new ( {String} serial_id )
- # new ( :path => device_path )
- # new ( :serial => serial_id )
+ # new ( path: device_path )
+ # new ( serial: serial_id )
#
# Returns new instance of +Blink1+
#
- def initialize option = nil
+ def initialize(option = nil)
case option
when Fixnum
open_by_id(option)
when Hash
- path = option[:path] || option["path"]
- serial = option[:serial] || option["serial"]
+ path = option[:path]
+ serial = option[:serial]
+
if path
open_by_path(path)
elsif serial
@@ -37,7 +38,8 @@ def initialize option = nil
else
open if option == true
end
- @millis ||= 300
+
+ @millis ||= 300
@delay_millis ||= 500
end
@@ -46,19 +48,20 @@ def initialize option = nil
# open ( {Fixnum} id ) { |blink1| }
# open ( {Boolean} autoopen ) { |blink1| }
# open ( {String} serial_id ) { |blink1| }
- # open ( :path => device_path ) { |blink1| }
- # open ( :serial => serial_id ) { |blink1| }
+ # open ( path: device_path ) { |blink1| }
+ # open ( serial: serial_id ) { |blink1| }
#
- # If block given, yieds new instance of +Blink1+.
+ # If block given, yields new instance of +Blink1+.
#
# If not, returns new +Blink1+
#
- def self.open option = nil, &block
- b = self.new(option)
+ def self.open(option = nil, &block)
+ b = new(option)
b.open if option.nil?
+
if block
begin
- b.instance_eval &block
+ b.instance_eval(&block)
ensure
b.close
end
@@ -70,11 +73,11 @@ def self.open option = nil, &block
#
# Blink with RGB value for +times+.
#
- def blink r, g, b, times
+ def blink(r, g, b, times)
times.times do
- self.fade_to_rgb(millis, r, g, b)
+ fade_to_rgb(millis, r, g, b)
self.class.sleep(delay_millis)
- self.fade_to_rgb(millis, 0, 0, 0)
+ fade_to_rgb(millis, 0, 0, 0)
self.class.sleep(delay_millis)
end
end
@@ -82,12 +85,12 @@ def blink r, g, b, times
#
# Flash random color for +times+.
#
- def random times
+ def random(times)
times.times do
r = rand(0xff)
g = rand(0xff)
b = rand(0xff)
- self.fade_to_rgb(millis, r, g, b)
+ fade_to_rgb(millis, r, g, b)
self.class.sleep(delay_millis)
end
end
@@ -96,32 +99,33 @@ def random times
# Turn LED white.
#
def on
- self.fade_to_rgb(millis, 0xff, 0xff, 0xff)
+ fade_to_rgb(millis, 0xff, 0xff, 0xff)
end
#
# Turn LED off.
#
def off
- self.fade_to_rgb(millis, 0, 0, 0)
+ fade_to_rgb(millis, 0, 0, 0)
end
#
# Alias for +read_pattern_line+.
#
- def [] index
- self.read_pattern_line(index)
+ def [](index)
+ read_pattern_line(index)
end
#
# Write pattern line with hash with key +fade_millis+, +r+, +g+, +b+.
#
- def []= index, prop
- fade_millis = prop[:fade_millis] || prop['fade_millis']
- r = prop[:r] || prop['r']
- g = prop[:g] || prop['g']
- b = prop[:b] || prop['b']
- self.write_pattern_line(index, fade_millis, r, g, b)
+ def []=(index, prop)
+ fade_millis = prop[:fade_millis]
+ r = prop[:r]
+ g = prop[:g]
+ b = prop[:b]
+
+ write_pattern_line(index, fade_millis, r, g, b)
end
#
@@ -129,17 +133,18 @@ def []= index, prop
#
def self.list
count = enumerate_vid_pid(vendor_id, product_id)
- i = 0
- devs = []
- while i < count do
+ i = 0
+ devs = []
+
+ while i < count
devs << {
- :id => i,
- :serial => cached_serial(i),
- :path => cached_path(i)
+ id: i,
+ serial: cached_serial(i),
+ path: cached_path(i)
}
i += 1
end
+
devs
end
-
end
diff --git a/rb-blink1.gemspec b/rb-blink1.gemspec
index de1bd05..85c37fd 100644
--- a/rb-blink1.gemspec
+++ b/rb-blink1.gemspec
@@ -25,8 +25,8 @@ Gem::Specification.new do |s|
s.add_development_dependency 'rspec'
s.add_development_dependency 'spork'
- s.files = `git ls-files`.split("\n").reject{|f| f =~ /^(\..+|Gemfile.*|Guardfile|)$/}
- s.extensions = ["ext/blink1/extconf.rb"]
+ s.files = `git ls-files`.split("\n").reject{|f| f =~ /^(\..+|Gemfile.*|Guardfile|)$/}
+ s.extensions = ["ext/blink1/extconf.rb"]
s.require_paths = ["lib", "ext"]
end
diff --git a/spec/blink1_spec.rb b/spec/blink1_spec.rb
index 1409c79..28bb97c 100644
--- a/spec/blink1_spec.rb
+++ b/spec/blink1_spec.rb
@@ -2,22 +2,36 @@
describe Blink1 do
- context 'native extention methods' do
+ describe 'native extention methods' do
- it 'returns vendor_id' do
- Blink1.vendor_id.should eql(10168)
+ describe 'vendor_id' do
+ subject { Blink1.vendor_id }
+ it { should be 10168 }
end
- it 'returns product_id' do
- Blink1.product_id.should eql(493)
+ describe 'product_id' do
+ subject { Blink1.product_id }
+ it { should be 493 }
end
end
- context 'class methods', :device => true do
+ context 'class methods', device: true do
- it 'returns list' do
- Blink1.list.is_a?(Array).should be_true
+ describe 'list' do
+ subject { Blink1.list }
+ it { should be_a_kind_of Array }
+ end
+
+ describe 'random' do
+ subject {
+ ret = nil
+ Blink1.open do|b1|
+ ret = b1.random 20
+ end
+ ret
+ }
+ it { should be_a_kind_of Fixnum }
end
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 735d58f..120bbb5 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -14,7 +14,7 @@
RSpec.configure do |config|
if ENV['CI']
- config.filter_run_excluding :device => true
+ config.filter_run_excluding device: true
end
end