rubysl-abbrev 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 02a3bee1379681b0c89511e711375e82f2a83936
4
+ data.tar.gz: acceaef513c3ff09ec2021881ca2a5c290dd1765
5
+ SHA512:
6
+ metadata.gz: 7f9f99ea62abc225cd3c226e0ec8e124d77de6bd1af42d5a5fde5df4561c72c22b1c2696c4ed3e4f203a83c9d2cfe029a0950663b38005978f04e7f5d4a31081
7
+ data.tar.gz: 78d394fa7631fd8e3983af944e33ce71883b24f56d1f7d7a110071d86aa8935da800b3f67acb41afbe2d17a9bdf4b90d7d8ad166717d56449636e29fde41bec6
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ env:
3
+ - RUBYLIB=lib
4
+ script: bundle exec mspec
5
+ rvm:
6
+ - 1.8.7
7
+ - rbx-nightly-18mode
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rubysl-abbrev.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2013, Brian Shirai
2
+ Copyright (c) 2001,2003 Akinori MUSHA <knu@iDaemons.org>
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+ 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+ 3. Neither the name of the library nor the names of its contributors may be
14
+ used to endorse or promote products derived from this software without
15
+ specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT,
21
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24
+ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Rubysl::Abbrev
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rubysl-abbrev'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rubysl-abbrev
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/abbrev.rb ADDED
@@ -0,0 +1 @@
1
+ require "rubysl/abbrev"
@@ -0,0 +1,2 @@
1
+ require "rubysl/abbrev/abbrev"
2
+ require "rubysl/abbrev/version"
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/env ruby
2
+ =begin
3
+ #
4
+ # Copyright (c) 2001,2003 Akinori MUSHA <knu@iDaemons.org>
5
+ #
6
+ # All rights reserved. You can redistribute and/or modify it under
7
+ # the same terms as Ruby.
8
+ #
9
+ # $Idaemons: /home/cvs/rb/abbrev.rb,v 1.2 2001/05/30 09:37:45 knu Exp $
10
+ # $RoughId: abbrev.rb,v 1.4 2003/10/14 19:45:42 knu Exp $
11
+ # $Id: abbrev.rb 11708 2007-02-12 23:01:19Z shyouhei $
12
+ =end
13
+
14
+ # Calculate the set of unique abbreviations for a given set of strings.
15
+ #
16
+ # require 'abbrev'
17
+ # require 'pp'
18
+ #
19
+ # pp Abbrev::abbrev(['ruby', 'rules']).sort
20
+ #
21
+ # <i>Generates:</i>
22
+ #
23
+ # [["rub", "ruby"],
24
+ # ["ruby", "ruby"],
25
+ # ["rul", "rules"],
26
+ # ["rule", "rules"],
27
+ # ["rules", "rules"]]
28
+ #
29
+ # Also adds an +abbrev+ method to class +Array+.
30
+
31
+ module Abbrev
32
+
33
+ # Given a set of strings, calculate the set of unambiguous
34
+ # abbreviations for those strings, and return a hash where the keys
35
+ # are all the possible abbreviations and the values are the full
36
+ # strings. Thus, given input of "car" and "cone", the keys pointing
37
+ # to "car" would be "ca" and "car", while those pointing to "cone"
38
+ # would be "co", "con", and "cone".
39
+ #
40
+ # The optional +pattern+ parameter is a pattern or a string. Only
41
+ # those input strings matching the pattern, or begging the string,
42
+ # are considered for inclusion in the output hash
43
+
44
+ def abbrev(words, pattern = nil)
45
+ table = {}
46
+ seen = Hash.new(0)
47
+
48
+ if pattern.is_a?(String)
49
+ pattern = /^#{Regexp.quote(pattern)}/ # regard as a prefix
50
+ end
51
+
52
+ words.each do |word|
53
+ next if (abbrev = word).empty?
54
+ while (len = abbrev.rindex(/[\w\W]\z/)) > 0
55
+ abbrev = word[0,len]
56
+
57
+ next if pattern && pattern !~ abbrev
58
+
59
+ case seen[abbrev] += 1
60
+ when 1
61
+ table[abbrev] = word
62
+ when 2
63
+ table.delete(abbrev)
64
+ else
65
+ break
66
+ end
67
+ end
68
+ end
69
+
70
+ words.each do |word|
71
+ next if pattern && pattern !~ word
72
+
73
+ table[word] = word
74
+ end
75
+
76
+ table
77
+ end
78
+
79
+ module_function :abbrev
80
+ end
81
+
82
+ class Array
83
+ # Calculates the set of unambiguous abbreviations for the strings in
84
+ # +self+. If passed a pattern or a string, only the strings matching
85
+ # the pattern or starting with the string are considered.
86
+ #
87
+ # %w{ car cone }.abbrev #=> { "ca" => "car", "car" => "car",
88
+ # "co" => "cone", "con" => cone",
89
+ # "cone" => "cone" }
90
+ def abbrev(pattern = nil)
91
+ Abbrev::abbrev(self, pattern)
92
+ end
93
+ end
94
+
95
+ if $0 == __FILE__
96
+ while line = gets
97
+ hash = line.split.abbrev
98
+
99
+ hash.sort.each do |k, v|
100
+ puts "#{k} => #{v}"
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,5 @@
1
+ module RubySL
2
+ module Abbrev
3
+ VERSION = "1.0.1"
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ require './lib/rubysl/abbrev/version'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "rubysl-abbrev"
6
+ spec.version = RubySL::Abbrev::VERSION
7
+ spec.authors = ["Brian Shirai"]
8
+ spec.email = ["brixen@gmail.com"]
9
+ spec.description = %q{Ruby standard library abbrev.}
10
+ spec.summary = %q{Ruby standard library abbrev.}
11
+ spec.homepage = "https://github.com/rubysl/rubysl-abbrev"
12
+ spec.license = "BSD"
13
+
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.3"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency "mspec", "~> 1.5"
22
+ end
@@ -0,0 +1,30 @@
1
+ require 'abbrev'
2
+
3
+ #test both Abbrev::abbrev and Array#abbrev in
4
+ #the same manner, as they're more or less aliases
5
+ #of one another
6
+
7
+ [["Abbrev::abbrev", lambda {|a| Abbrev::abbrev(a)}],
8
+ ["Array#abbrev", lambda {|a| a.abbrev}]
9
+ ].each do |(name, func)|
10
+
11
+ describe name do
12
+ it "returns a hash of all unambiguous abbreviations of the array of strings passed in" do
13
+ func.call(['ruby', 'rules']).should == {"rub" => "ruby",
14
+ "ruby" => "ruby",
15
+ "rul" => "rules",
16
+ "rule" => "rules",
17
+ "rules" => "rules"}
18
+
19
+ func.call(["car", "cone"]).should == {"ca" => "car",
20
+ "car" => "car",
21
+ "co" => "cone",
22
+ "con" => "cone",
23
+ "cone" => "cone"}
24
+ end
25
+
26
+ it "returns an empty hash when called on an empty array" do
27
+ func.call([]).should == {}
28
+ end
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubysl-abbrev
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Brian Shirai
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ description: Ruby standard library abbrev.
56
+ email:
57
+ - brixen@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .travis.yml
64
+ - Gemfile
65
+ - LICENSE
66
+ - README.md
67
+ - Rakefile
68
+ - lib/abbrev.rb
69
+ - lib/rubysl/abbrev.rb
70
+ - lib/rubysl/abbrev/abbrev.rb
71
+ - lib/rubysl/abbrev/version.rb
72
+ - rubysl-abbrev.gemspec
73
+ - spec/abbrev_spec.rb
74
+ homepage: https://github.com/rubysl/rubysl-abbrev
75
+ licenses:
76
+ - BSD
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.0.7
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Ruby standard library abbrev.
98
+ test_files:
99
+ - spec/abbrev_spec.rb