natcmp 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ === 1.4.0 2010-01-19
2
+
3
+ * 2 major enhancements:
4
+ * First gem release
5
+ * natcmp() function now in Natcmp module, rather than extending String class
@@ -0,0 +1,11 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.rdoc
4
+ Rakefile
5
+ lib/natcmp.rb
6
+ script/console
7
+ script/console.cmd
8
+ script/destroy
9
+ script/destroy.cmd
10
+ script/generate
11
+ script/generate.cmd
@@ -0,0 +1,39 @@
1
+ = natcmp
2
+
3
+ * http://rubyforge.org/projects/natcmp/
4
+
5
+ == DESCRIPTION:
6
+
7
+ Natural order string comparison module.
8
+
9
+ == SYNOPSIS:
10
+
11
+ Natural Order Sting Comparison is a way of comparing strings "naturally".
12
+ e.g. "somthing1" < "something2" < "something10"
13
+ which does not follow alpabetically.
14
+
15
+ == REQUIREMENTS:
16
+
17
+ * Ruby :)
18
+
19
+ == INSTALL:
20
+
21
+ * sudo gem install
22
+
23
+ == LICENSE:
24
+
25
+ This software is provided 'as-is', without any express or implied
26
+ warranty. In no event will the authors be held liable for any damages
27
+ arising from the use of this software.
28
+
29
+ Permission is granted to anyone to use this software for any purpose,
30
+ including commercial applications, and to alter it and redistribute it
31
+ freely, subject to the following restrictions:
32
+
33
+ 1. The origin of this software must not be misrepresented; you must not
34
+ claim that you wrote the original software. If you use this software
35
+ in a product, an acknowledgment in the product documentation would be
36
+ appreciated but is not required.
37
+ 2. Altered source versions must be plainly marked as such, and must not be
38
+ misrepresented as being the original software.
39
+ 3. This notice may not be removed or altered from any source distribution.
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/natcmp'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 'natcmp' do
14
+ self.developer 'Alan Davies', 'alan n davies at gmail com'
15
+ #self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
16
+ self.rubyforge_name = self.name # TODO this is default value
17
+ # self.extra_deps = [['activesupport','>= 2.0.2']]
18
+
19
+ end
20
+
21
+ require 'newgem/tasks'
22
+ Dir['tasks/**/*.rake'].each { |t| load t }
23
+
24
+ # TODO - want other tests/tasks run by default? Add them to the list
25
+ # remove_task :default
26
+ # task :default => [:spec, :features]
@@ -0,0 +1,61 @@
1
+ # == Synopsis
2
+ #
3
+ # Natural order comparison of two strings
4
+ # e.g. "my_prog_v1.1.0" < "my_prog_v1.2.0" < "my_prog_v1.10.0"
5
+ # which does not follow alphabetically
6
+ #
7
+ # == Acknowledgments
8
+ #
9
+ # Based on Martin Pool's "Natural Order String Comparison" originally written in C
10
+ # http://sourcefrog.net/projects/natsort/
11
+ #
12
+ # == Copyright
13
+ #
14
+ # This implementation is Copyright (C) 2003, 2008, 2009 by Alan Davies.
15
+ #
16
+ # == License
17
+ #
18
+ # This software is provided 'as-is', without any express or implied
19
+ # warranty. In no event will the authors be held liable for any damages
20
+ # arising from the use of this software.
21
+ #
22
+ # Permission is granted to anyone to use this software for any purpose,
23
+ # including commercial applications, and to alter it and redistribute it
24
+ # freely, subject to the following restrictions:
25
+ #
26
+ # 1. The origin of this software must not be misrepresented; you must not
27
+ # claim that you wrote the original software. If you use this software
28
+ # in a product, an acknowledgment in the product documentation would be
29
+ # appreciated but is not required.
30
+ # 2. Altered source versions must be plainly marked as such, and must not be
31
+ # misrepresented as being the original software.
32
+ # 3. This notice may not be removed or altered from any source distribution.
33
+ module Natcmp
34
+ VERSION = "1.4.0"
35
+
36
+ # 'Natural order' comparison of two strings.
37
+ #
38
+ # e.g. "my_prog_v1.1.0" < "my_prog_v1.2.0" < "my_prog_v1.10.0"
39
+ #
40
+ # which does not follow alphabetically
41
+ def self.natcmp(str1, str2, ignoreCase=true)
42
+ # Split the strings into digits and non-digits
43
+ strArrays = [str1,str2].collect do |str|
44
+ str = str.downcase if ignoreCase
45
+ str.tr(" \t\r\n", '').split(/(\d+)/)
46
+ end
47
+
48
+ # Get length of smallest array
49
+ minSize = strArrays.min_by { |arr| arr.size }.size
50
+
51
+ # Loop through all the digit parts and convert to integers if neither of them begin with a zero
52
+ 1.step(minSize-1, 2) do |i|
53
+ unless strArrays.any? { |arr| arr[i] =~ /^0/ }
54
+ strArrays.each { |arr| arr[i] = arr[i].to_i }
55
+ end
56
+ end
57
+
58
+ strArrays[0] <=> strArrays[1]
59
+ end
60
+
61
+ end # module Natcmp
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/natcmp.rb'}"
9
+ puts "Loading natcmp gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1 @@
1
+ @ruby script/console %*
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -0,0 +1 @@
1
+ @ruby script/destroy %*
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1 @@
1
+ @ruby script/generate %*
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: natcmp
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Alan Davies
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-19 00:00:00 +00:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rubyforge
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.0.3
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: gemcutter
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: hoe
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.5.0
44
+ version:
45
+ description: Natural order string comparison module.
46
+ email:
47
+ - alan n davies at gmail com
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - History.txt
54
+ - Manifest.txt
55
+ files:
56
+ - History.txt
57
+ - Manifest.txt
58
+ - README.rdoc
59
+ - Rakefile
60
+ - lib/natcmp.rb
61
+ - script/console
62
+ - script/console.cmd
63
+ - script/destroy
64
+ - script/destroy.cmd
65
+ - script/generate
66
+ - script/generate.cmd
67
+ has_rdoc: true
68
+ homepage: http://rubyforge.org/projects/natcmp/
69
+ licenses: []
70
+
71
+ post_install_message:
72
+ rdoc_options:
73
+ - --main
74
+ - README.rdoc
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ version:
89
+ requirements: []
90
+
91
+ rubyforge_project: natcmp
92
+ rubygems_version: 1.3.5
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: Natural order string comparison module.
96
+ test_files: []
97
+