rangeary 1.0.1 → 2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ChangeLog +18 -0
- data/Makefile +2 -1
- data/News +4 -0
- data/README.ja.rdoc +461 -260
- data/lib/rangeary/util/hash_inf.rb +233 -0
- data/lib/rangeary/util.rb +727 -0
- data/lib/rangeary.rb +1420 -0
- data/rangeary.gemspec +51 -0
- data/test/tee_io.rb +111 -0
- data/test/test_rangeary.rb +400 -79
- metadata +25 -19
- data/lib/rangeary/rangeary.rb +0 -1643
data/rangeary.gemspec
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
require 'date'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{rangeary}.sub(/.*/){|c| (c == File.basename(Dir.pwd)) ? c : raise("ERROR: s.name=(#{c}) in gemspec seems wrong!")}
|
8
|
+
s.version = "2.0"
|
9
|
+
# s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
10
|
+
# s.executables << 'hola'
|
11
|
+
# s.bindir = 'bin'
|
12
|
+
s.authors = ["Masa Sakano"]
|
13
|
+
s.date = %q{2022-09-08}.sub(/.*/){|c| (Date.parse(c) == Date.today) ? c : raise("ERROR: s.date=(#{c}) is not today!")}
|
14
|
+
s.summary = %q{Rangeary - class to represent any 1-dimensional multiple-range}
|
15
|
+
s.description = %q{Rangeary is a sub-class of Array and represents any 1-dimensional multiple-range, for example, (x<4 and 7<x<=9) or (x<="c" and "f"<=x), where the infinities can be abstract like nil or be defined by the user. All the standard logical operations, including negation, conjunction and disjunction, are supported and can be used with conventional Ruby-style operators. Each range is represented as RangeExtd class (Extended Range), which is a sub-class of Range and supports exclude-begin and open-ended (to Infinity) ranges, and is downloadable from https://rubygems.org/gems/range_extd}
|
16
|
+
# s.email = %q{abc@example.com}
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
# "LICENSE",
|
19
|
+
#"README.en.rdoc",
|
20
|
+
"README.ja.rdoc",
|
21
|
+
]
|
22
|
+
s.license = 'MIT'
|
23
|
+
s.files = FileList['.gitignore','lib/**/*.rb','[A-Z]*', 'test/**/*.rb'].to_a.delete_if{ |f|
|
24
|
+
ret = false
|
25
|
+
arignore = IO.readlines('.gitignore')
|
26
|
+
arignore.map{|i| i.chomp}.each do |suffix|
|
27
|
+
if File.fnmatch(suffix, File.basename(f))
|
28
|
+
ret = true
|
29
|
+
break
|
30
|
+
end
|
31
|
+
end
|
32
|
+
ret
|
33
|
+
}
|
34
|
+
s.files.reject! { |fn| File.symlink? fn }
|
35
|
+
|
36
|
+
s.add_runtime_dependency 'range_extd', '~> 2' # Range#equiv? introduced in 0.4.0; beginless Range introduced in 2.0
|
37
|
+
# s.add_runtime_dependency 'library', '~> 2.2', '>= 2.2.1' # 2.2.1 <= Ver < 2.3.0
|
38
|
+
# s.add_development_dependency "bourne", [">= 0"]
|
39
|
+
s.homepage = %q{https://www.wisebabel.com}
|
40
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
41
|
+
|
42
|
+
# s.require_paths = ["lib"]
|
43
|
+
s.required_ruby_version = '>= 2.7' # required >= 2.6 for testing.
|
44
|
+
s.test_files = Dir['test/**/*.rb']
|
45
|
+
s.test_files.reject! { |fn| File.symlink? fn }
|
46
|
+
# s.requirements << 'libmagick, v6.0' # Simply, info to users.
|
47
|
+
# s.rubygems_version = %q{1.3.5} # This is always set automatically!!
|
48
|
+
|
49
|
+
s.metadata["yard.run"] = "yri" # use "yard" to build full HTML docs.
|
50
|
+
end
|
51
|
+
|
data/test/tee_io.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
|
2
|
+
# Taken from <https://gist.github.com/masasakano/789030a7dc5313bd343b2de967a93200>
|
3
|
+
|
4
|
+
require "tempfile"
|
5
|
+
|
6
|
+
# TeeIO to "tee" (or splice) an IO
|
7
|
+
#
|
8
|
+
# Basically this overwrites IO#write .
|
9
|
+
#
|
10
|
+
# Note this does not capture IO#syswrite
|
11
|
+
#
|
12
|
+
# The main part but {TeeIO.suppress_io} is taken from
|
13
|
+
# {https://stackoverflow.com/a/9439298/3577922}
|
14
|
+
#
|
15
|
+
# Main use of this class is {TeeIO.suppress_io}
|
16
|
+
#
|
17
|
+
# @author Masa Sakano
|
18
|
+
#
|
19
|
+
class TeeIO < IO
|
20
|
+
def initialize io_orig, io_file
|
21
|
+
@orig = io_orig
|
22
|
+
@file = io_file
|
23
|
+
end
|
24
|
+
def write string
|
25
|
+
@file.write string
|
26
|
+
@orig.write string
|
27
|
+
end
|
28
|
+
|
29
|
+
# IO outputs are suppressed in the given block with a copy/alternative provided.
|
30
|
+
#
|
31
|
+
# If +ENV['DISPLAY_STDERR']+ (or the name provided) is set,
|
32
|
+
# the original is output as normal, while it is redirected to IO, too.
|
33
|
+
#
|
34
|
+
# This is especially designed for testing framework. In testing,
|
35
|
+
# you may deliberately test lots of situations where messages
|
36
|
+
# are printed to the terminal. You may want to suppress them,
|
37
|
+
# providing the messages are what you expect. But it is laborious
|
38
|
+
# to write test code to check all the messages, and so you may just
|
39
|
+
# want to suppress all. However, from time to time you may want to
|
40
|
+
# switch to see the messages to make sure nothing unexpected is happening.
|
41
|
+
#
|
42
|
+
# This method provides the flexibility. You can suppress the message,
|
43
|
+
# while you can still access them if you want, and you can switch off
|
44
|
+
# suppressing by providing an environmental variable.
|
45
|
+
#
|
46
|
+
# @note For the given IO, IO#sync=true should be set beforehand.
|
47
|
+
#
|
48
|
+
# @example suppressing STDOUT
|
49
|
+
# puts "1: This is displayed."
|
50
|
+
# suppress_io($stdout, envanme: "DISPLAY_STDOUT"){ |iorw|
|
51
|
+
# puts "2: This is suppressed."
|
52
|
+
# iorw.rewind
|
53
|
+
# $stderr.print "3: Message read from IO: "
|
54
|
+
# $stderr.puts iorw.read # => "2: This is suppressed."
|
55
|
+
# }
|
56
|
+
# puts "4: This is displayed."
|
57
|
+
#
|
58
|
+
# @see https://gist.github.com/moertel/11091573
|
59
|
+
#
|
60
|
+
# @param ioin [IO] IO to suppress
|
61
|
+
# @param envname [String] Name of the Environmental variable
|
62
|
+
# @yield [IO] the given IO is redirected (or copied)
|
63
|
+
def self.suppress_io(ioin=$stderr, envname: 'DISPLAY_STDERR')
|
64
|
+
display_stderr = (ENV[envname] && !ENV[envname].empty? && ENV[envname] != "0")
|
65
|
+
iorw = Tempfile.new(File.basename(__FILE__))
|
66
|
+
iorw.sync = true
|
67
|
+
original_stderr = $stderr.clone
|
68
|
+
|
69
|
+
tee = TeeIO.new $stderr, iorw
|
70
|
+
if display_stderr
|
71
|
+
$stderr = tee
|
72
|
+
else
|
73
|
+
#$stderr.reopen File.new('/dev/null', 'w')
|
74
|
+
$stderr.reopen iorw
|
75
|
+
end
|
76
|
+
yield(iorw)
|
77
|
+
ensure
|
78
|
+
if display_stderr
|
79
|
+
$stderr = original_stderr
|
80
|
+
else
|
81
|
+
$stderr.reopen original_stderr
|
82
|
+
end
|
83
|
+
iorw.close if iorw
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
############### Demonstrations ###############
|
89
|
+
|
90
|
+
if $0 == __FILE__
|
91
|
+
$stdout.sync = true
|
92
|
+
$stderr.sync = true # recommended!
|
93
|
+
$stderr.puts "1: Before suppression."
|
94
|
+
TeeIO.suppress_io{ |iorw|
|
95
|
+
$stderr.puts "2: This is suppressed."
|
96
|
+
print "3: Message read from IO: "
|
97
|
+
iorw.rewind
|
98
|
+
puts iorw.read
|
99
|
+
}
|
100
|
+
$stderr.puts "4: After first suppression."
|
101
|
+
|
102
|
+
ENV['DISPLAY_STDERR'] = "1"
|
103
|
+
TeeIO.suppress_io{ |iorw|
|
104
|
+
$stderr.puts "5: This is not suppressed."
|
105
|
+
print "6: Message read from IO: "
|
106
|
+
iorw.rewind
|
107
|
+
puts iorw.read
|
108
|
+
}
|
109
|
+
$stderr.puts "7: After second suppression."
|
110
|
+
$stderr.puts "Messages 1-7 except 2 should be printed (the order may vary)."
|
111
|
+
end
|