This repository has been archived by the owner on May 21, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2bbda18
Showing
10 changed files
with
216 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
=== 0.0.1 2012-1-14 | ||
|
||
* 1 major enhancement: | ||
* Initial release | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
History.rdoc | ||
Manifest.txt | ||
README.rdoc | ||
Rakefile | ||
example.rb | ||
lib/vertere/core.rb | ||
lib/vertere/import.rb | ||
lib/vertere.rb | ||
test/test_helper.rb | ||
test/test_vertere.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
= vertere | ||
|
||
* http://github.com/kachick/vertere | ||
* https://rubygems.org/gems/vertere | ||
* http://rubyforge.org/projects/vertere | ||
|
||
== DESCRIPTION | ||
|
||
wrapper for inverted comparisons | ||
|
||
== FEATURES | ||
* easy get objects for inverted comparisons | ||
|
||
== SYNOPSIS | ||
|
||
* setup | ||
require 'vertere' | ||
|
||
* an approach for [ruby-talk:392128] | ||
# http://www.ruby-forum.com/topic/3418285 | ||
|
||
NUMBER_CHARS=('0'..'11').map(&:freeze).freeze | ||
#=> ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"] | ||
|
||
NUMBER_CHARS.grep(/0/) | ||
#=> ["0", "10"] | ||
|
||
NUMBER_CHARS.grep(/0/.for_!) | ||
#=> ["1", "2", "3", "4", "5", "6", "7", "8", "9", "11"] | ||
|
||
* and more | ||
NUMBER_CHARS.sort_by{|s|s.to_i.for_!} | ||
#=> ["11", "10", "9", "8", "7", "6", "5", "4", "3", "2", "1", "0"] | ||
|
||
== REQUIREMENTS | ||
|
||
* Ruby 1.9.2 and later (tested 1.9.2, 1.9.3) | ||
|
||
== INSTALL | ||
|
||
* sudo gem install vertere | ||
|
||
== LICENSE | ||
|
||
(The MIT License) | ||
|
||
Copyright (c) 2012 Kenichi Kamiya | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
'Software'), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'rubygems' | ||
gem 'hoe', '>= 2.12.4' | ||
require 'hoe' | ||
require 'fileutils' | ||
|
||
Hoe.plugin :newgem | ||
# Hoe.plugin :website | ||
# Hoe.plugin :cucumberfeatures | ||
|
||
# Generate all the Rake tasks | ||
# Run 'rake -T' to see list of generated tasks (from gem root directory) | ||
$hoe = Hoe.spec 'vertere' do | ||
developer 'Kenichi Kamiya', 'kachick1+ruby@gmail.com' | ||
self.rubyforge_name = self.name | ||
require_ruby_version '>= 1.9.2' | ||
dependency 'yard', '~> 0.7.4', :development | ||
end | ||
|
||
require 'newgem/tasks' | ||
Dir['tasks/**/*.rake'].each { |t| load t } | ||
|
||
# TODO - want other tests/tasks run by default? Add them to the list | ||
# remove_task :default | ||
# task :default => [:spec, :features] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/ruby -w | ||
|
||
require_relative 'lib/vertere' | ||
|
||
# an approach for [ruby-talk:392128] | ||
# http://www.ruby-forum.com/topic/3418285 | ||
|
||
NUMBER_CHARS=('0'..'11').map(&:freeze).freeze | ||
p NUMBER_CHARS | ||
p NUMBER_CHARS.grep(/0/) | ||
p(/0/ =~ '0') | ||
p NUMBER_CHARS.grep(/0/.for_!) | ||
p(/0/.for_! =~ '0') | ||
p NUMBER_CHARS.grep(/0/) | ||
p NUMBER_CHARS.sort_by(&:to_i) | ||
p NUMBER_CHARS.sort_by{|s|s.to_i.for_!} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright (C) 2012 Kenichi Kamiya | ||
|
||
require_relative 'vertere/core' | ||
require_relative 'vertere/import' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
require 'delegate' | ||
|
||
# @author Kenichi Kamiya | ||
module Vertere | ||
|
||
VERSION = '0.0.1'.freeze | ||
|
||
# @author Kenichi Kamiya | ||
module ObjectExtension | ||
def for_vertere | ||
::Vertere.for_object self | ||
end | ||
|
||
alias_method :for_!, :for_vertere | ||
|
||
def comparison_inverted? | ||
false | ||
end | ||
end | ||
|
||
class << self | ||
def for_object(original) | ||
invereted = original.clone | ||
rescue SecurityError | ||
invereted = original.dup | ||
rescue TypeError | ||
invereted = SimpleDelegator.new original | ||
ensure | ||
invereted.singleton_class.class_eval do | ||
%w[== === =~].each do |operator| | ||
if original.respond_to? operator | ||
define_method operator do |other| | ||
! (super other) | ||
end | ||
end | ||
end | ||
|
||
if original.respond_to? :<=> | ||
def <=>(other) | ||
r = super other | ||
r && (- r) | ||
end | ||
end | ||
|
||
def comparison_inverted? | ||
true | ||
end | ||
end | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require_relative 'core' | ||
|
||
class Object | ||
include Vertere::ObjectExtension | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require 'stringio' | ||
require 'test/unit' | ||
require File.dirname(__FILE__) + '/../lib/vertere' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
$VERBOSE = true | ||
require File.dirname(__FILE__) + '/test_helper.rb' | ||
|
||
class TestVertere < Test::Unit::TestCase | ||
NUMBER_CHARS=('0'..'11').map(&:freeze).freeze | ||
|
||
def test_compare | ||
assert_equal(["0", "10"], NUMBER_CHARS.grep(/0/)) | ||
assert_equal((NUMBER_CHARS - ["0", "10"]), NUMBER_CHARS.grep(/0/.for_!)) | ||
assert_equal(false, (/0/.for_! =~ '0')) | ||
assert_equal(["0", "10"], NUMBER_CHARS.grep(/0/)) # check not bloken | ||
assert_equal(NUMBER_CHARS, NUMBER_CHARS.sort_by(&:to_i)) | ||
assert_equal(NUMBER_CHARS.reverse, NUMBER_CHARS.sort_by{|s|s.to_i.for_!}) | ||
end | ||
|
||
def test_methods_minimum_defined | ||
obj = Object.new | ||
assert_equal(true, obj.respond_to?(:=~)) | ||
obj.singleton_class.class_eval do | ||
undef_method :=~ | ||
end | ||
assert_equal(false, obj.respond_to?(:=~)) | ||
assert_equal(false, obj.for_!.respond_to?(:=~)) | ||
end | ||
|
||
def test_check_methods | ||
obj = Object.new | ||
assert_equal(false, obj.comparison_inverted?) | ||
assert_equal(true, obj.for_!.comparison_inverted?) | ||
end | ||
end |