From 999cf3b2154f5afc786c3dc237b4edcf562f5422 Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Mon, 23 Dec 2013 10:18:58 -0800 Subject: [PATCH 1/7] update from .rvmrc to .ruby-version --- .ruby-gemset | 1 + .rvmrc | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 .ruby-gemset delete mode 100644 .rvmrc 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 From d3ea54f39f7bc3490b309d1d785fa4a33817f4c8 Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Mon, 23 Dec 2013 10:49:40 -0800 Subject: [PATCH 2/7] Update blink1.rb --- lib/blink1.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/blink1.rb b/lib/blink1.rb index 00cb966..4e1e00a 100644 --- a/lib/blink1.rb +++ b/lib/blink1.rb @@ -49,7 +49,7 @@ def initialize option = nil # 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+ # From 44485e6c8d9a3541ac008d65298a4023f842dbf4 Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Mon, 23 Dec 2013 11:10:59 -0800 Subject: [PATCH 3/7] code cleanup - 1.9.3+ hash syntax, spacing, alignment --- Rakefile | 6 ++-- lib/blink1.rb | 73 ++++++++++++++++++++++++--------------------- spec/blink1_spec.rb | 2 +- 3 files changed, 42 insertions(+), 39 deletions(-) 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/spec/blink1_spec.rb b/spec/blink1_spec.rb index 1409c79..8d75c03 100644 --- a/spec/blink1_spec.rb +++ b/spec/blink1_spec.rb @@ -14,7 +14,7 @@ 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 From 5bcb8ef8b2eea53e853941ab5236449592b98d89 Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Mon, 23 Dec 2013 11:12:55 -0800 Subject: [PATCH 4/7] lingering <1.9.3 hash syntax --- Gemfile | 2 +- rb-blink1.gemspec | 4 ++-- spec/spec_helper.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) 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/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/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 From 0c19bc33cfa145abedd5756d6eb43adbb4e08dc2 Mon Sep 17 00:00:00 2001 From: Atsushi Nagase Date: Wed, 2 Jul 2014 11:18:04 +0900 Subject: [PATCH 5/7] Update spec --- spec/blink1_spec.rb | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/spec/blink1_spec.rb b/spec/blink1_spec.rb index 1409c79..08ec1e8 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 - 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 From e4e734511dbf0d231f32e21578c98367368137eb Mon Sep 17 00:00:00 2001 From: Atsushi Nagase Date: Wed, 2 Jul 2014 11:23:57 +0900 Subject: [PATCH 6/7] Update rvm in .travis.yml --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4f21a80..d50ed2b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,8 @@ language: ruby env: CODECLIMATE_REPO_TOKEN=ea524e4acf0abd2a5d396cc239710de238314e5bfe3af472baca56a88f7b7ec1 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 From bc10c7eb7ef5aabba6296c79078c4bd3286f05a2 Mon Sep 17 00:00:00 2001 From: Atsushi Nagase Date: Wed, 2 Jul 2014 11:45:02 +0900 Subject: [PATCH 7/7] Set SPEC_OPTS --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d50ed2b..c71f59b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: ruby -env: CODECLIMATE_REPO_TOKEN=ea524e4acf0abd2a5d396cc239710de238314e5bfe3af472baca56a88f7b7ec1 +env: CODECLIMATE_REPO_TOKEN=ea524e4acf0abd2a5d396cc239710de238314e5bfe3af472baca56a88f7b7ec1 SPEC_OPTS='--format documentation' rvm: - "1.9.3" - "2.0.0"