positionrange 0.6.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.
data/README.txt ADDED
@@ -0,0 +1,87 @@
1
+ = Position Range -- Ranges with attributes that can be juggled
2
+
3
+ Allows you to assign random attributes to ranges and juggle them in
4
+ lists. Also adds parsing from string, but most intereting when used in
5
+ a PositionRange::List.
6
+
7
+ There standard set operations can be applied to it, like additions,
8
+ substractions and intersections. In addition you can also get the
9
+ combined size of all the ranges in the list. And cluster overlapping
10
+ ranges, maintaining the attributes (more below).
11
+
12
+ PositionRange is a library by the LogiLogi Foundation, extracted from
13
+ http://www.logilogi.org (http://foundation.logilogi.org).
14
+
15
+ == Usage
16
+
17
+ You can assign random attributes to PositionRanges.
18
+
19
+ r = PositionRange.new(1,10, :cow => 'moo')
20
+
21
+ r.cow => 'moo'
22
+
23
+ You can also create a PositionRange::List directly from a string.
24
+
25
+ l = PositionRange::List.from_s('0,10:5,15')
26
+
27
+ Then you can get the combined size.
28
+
29
+ l.range_size => 20
30
+
31
+ Or line up overlaps.
32
+
33
+ l.line_up_overlaps!.to_s => '0,5:5,10:5,10:10,15'
34
+
35
+ Clustering overlaps maintains attributes.
36
+
37
+ l = PositionRange::List.new([
38
+ PositionRange.new(0,10, :cow => 'moo'),
39
+ PositionRange.new(5,15, :goat => 7)
40
+ ])
41
+
42
+ l.cluster_overlaps => [
43
+ PositionRange::List.new([
44
+ PositionRange.new(0,5, :cow => 'moo')]),
45
+ PositionRange::List.new([
46
+ PositionRange.new(5,10, :cow => 'moo'),
47
+ PositionRange.new(5,10, :goat => 7)]),
48
+ PositionRange::List.new([
49
+ PositionRange.new(10,15, :goat => 7)])
50
+ ]
51
+
52
+ == Download
53
+
54
+ The latest version of Position Range can be found at:
55
+
56
+ * http://rubyforge.org/frs/?group_id=7564
57
+
58
+ Documentation can be found at:
59
+
60
+ * http://positionrange.rubyonrails.org
61
+
62
+ == Installation
63
+
64
+ You can install Position Range with the following command:
65
+
66
+ % [sudo] gem install positionrange
67
+
68
+ Or from its distribution directory with:
69
+
70
+ % [sudo] ruby install.rb
71
+
72
+ == License
73
+
74
+ Position Range is released under the GNU Affero GPL licence.
75
+
76
+ * http://www.fsf.org/licensing/licenses/agpl-3.0.html
77
+
78
+ == Support
79
+
80
+ The Position Range homepage is http://positionrange.rubyforge.org.
81
+
82
+ For the latest news on Position Range:
83
+
84
+ * http://foundation.logilogi.org/tags/PositionRange
85
+
86
+ Feel free to submit commits or feature requests. If you send a patch,
87
+ remember to update the corresponding unit tests.
data/Rakefile ADDED
@@ -0,0 +1,98 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+ require 'rake/contrib/sshpublisher'
8
+ require File.join(File.dirname(__FILE__), 'lib', 'position_range', 'version')
9
+
10
+ PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
11
+ PKG_NAME = 'positionrange'
12
+ PKG_VERSION = PositionRange::VERSION::STRING + PKG_BUILD
13
+ PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
14
+
15
+ RELEASE_NAME = "REL #{PKG_VERSION}"
16
+
17
+ RUBY_FORGE_PROJECT = "positionrange"
18
+ RUBY_FORGE_USER = "wybow"
19
+
20
+ desc "Default Task"
21
+ task :default => [ :test ]
22
+
23
+ # Run the unit tests
24
+ Rake::TestTask.new { |t|
25
+ t.libs << "test"
26
+ t.pattern = 'test/*_test.rb'
27
+ t.verbose = true
28
+ t.warning = false
29
+ }
30
+
31
+ # Generate the RDoc documentation
32
+ Rake::RDocTask.new { |rdoc|
33
+ rdoc.rdoc_dir = 'doc'
34
+ rdoc.title = "Position Range -- Ranges with attributes that can be juggled"
35
+ rdoc.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object'
36
+ rdoc.options << '--charset' << 'utf-8'
37
+ rdoc.rdoc_files.include('README.txt', 'CHANGELOG.txt')
38
+ rdoc.rdoc_files.include('lib/position_range.rb')
39
+ rdoc.rdoc_files.include('lib/position_range/*.rb')
40
+ }
41
+
42
+ # Create compressed packages
43
+ spec = Gem::Specification.new do |s|
44
+ s.platform = Gem::Platform::RUBY
45
+ s.name = PKG_NAME
46
+ s.summary = "Ranges with attributes that can be juggled."
47
+ s.description = %q{Allows you to assign random attributes to ranges and juggle them in lists.}
48
+ s.version = PKG_VERSION
49
+
50
+ s.author = "Wybo Wiersma"
51
+ s.email = "wybo@logilogi.org"
52
+ s.rubyforge_project = "positionrange"
53
+ s.homepage = "http://positionrange.rubyforge.org"
54
+
55
+ s.has_rdoc = true
56
+ s.requirements << 'none'
57
+ s.require_path = 'lib'
58
+
59
+ s.files = [ "Rakefile", "install.rb", "README.txt", "CHANGELOG.txt", "LICENSE.txt" ]
60
+ s.files = s.files + Dir.glob( "lib/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
61
+ s.files = s.files + Dir.glob( "test/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
62
+ end
63
+
64
+ Rake::GemPackageTask.new(spec) do |p|
65
+ p.gem_spec = spec
66
+ p.need_tar = true
67
+ p.need_zip = true
68
+ end
69
+
70
+ desc "Publish the docs, gem, and release files"
71
+ task :publish => [:release, :pgem, :pdoc] do
72
+ puts 'Published gem'
73
+ end
74
+
75
+ desc "Publish the gem"
76
+ task :pgem => [:package] do
77
+ Rake::SshFilePublisher.new("gems.rubyonrails.org",
78
+ "/u/sites/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
79
+ `ssh gems.rubyonrails.org '/u/sites/gems/gemupdate.sh'`
80
+ end
81
+
82
+ desc "Publish the API documentation"
83
+ task :pdoc => [:rdoc] do
84
+ sh "rsync -azv --no-perms --no-times doc/*" +
85
+ " rubyforge.org:/var/www/gforge-projects/positionrange"
86
+ end
87
+
88
+ desc "Publish the release files to RubyForge."
89
+ task :release => [ :package ] do
90
+ require 'rubyforge'
91
+ require 'rake/contrib/rubyforgepublisher'
92
+
93
+ packages = %w( gem tgz zip ).collect{ |ext| "pkg/#{PKG_NAME}-#{PKG_VERSION}.#{ext}" }
94
+
95
+ rubyforge = RubyForge.new.configure
96
+ rubyforge.login
97
+ rubyforge.add_release(PKG_NAME, PKG_NAME, "REL #{PKG_VERSION}", *packages)
98
+ end
data/install.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'rbconfig'
2
+ require 'find'
3
+ require 'ftools'
4
+
5
+ include Config
6
+
7
+ # this was adapted from rdoc's install.rb by way of Log4r
8
+
9
+ $sitedir = CONFIG["sitelibdir"]
10
+ unless $sitedir
11
+ version = CONFIG["MAJOR"] + "." + CONFIG["MINOR"]
12
+ $libdir = File.join(CONFIG["libdir"], "ruby", version)
13
+ $sitedir = $:.find {|x| x =~ /site_ruby/ }
14
+ if !$sitedir
15
+ $sitedir = File.join($libdir, "site_ruby")
16
+ elsif $sitedir !~ Regexp.quote(version)
17
+ $sitedir = File.join($sitedir, version)
18
+ end
19
+ end
20
+
21
+ # the actual gruntwork
22
+ Dir.chdir("lib")
23
+
24
+ Find.find("position_range", "position_range.rb") { |f|
25
+ if f[-3..-1] == ".rb"
26
+ File::install(f, File.join($sitedir, *f.split(/\//)), 0644, true)
27
+ else
28
+ File::makedirs(File.join($sitedir, *f.split(/\//)))
29
+ end
30
+ }
@@ -0,0 +1,28 @@
1
+ #--#
2
+ # Copyright: (c) 2006-2008 The LogiLogi Foundation <foundation@logilogi.org>
3
+ #
4
+ # License:
5
+ # This file is part of the PositionRange Library. PositionRange is Free
6
+ # Software. You can run/distribute/modify PositionRange under the terms of
7
+ # the GNU Affero General Public License version 3. The Affero GPL states
8
+ # that running a modified version or a derivative work also requires you to
9
+ # make the sourcecode of that work available to everyone that can interact
10
+ # with it. We chose the Affero GPL to ensure that PositionRange remains open
11
+ # and libre (LICENSE.txt contains the full text of the legally binding
12
+ # license).
13
+ #++#
14
+ #
15
+ # This Error is raised if positions are out of range.
16
+
17
+ class PositionRange::Error < StandardError
18
+ attr_accessor :from_range, :to_range
19
+
20
+ def initialize(from_range, to_range)
21
+ @from_range = from_range
22
+ @to_range = to_range
23
+ end
24
+
25
+ def message
26
+ super.to_s + ': ' + @from_range.to_s + ',' + @to_range.to_s
27
+ end
28
+ end