chars 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/.document CHANGED
@@ -1,4 +1,4 @@
1
1
  lib/**/*.rb
2
2
  -
3
- ChangeLog.*
3
+ ChangeLog.md
4
4
  LICENSE.txt
@@ -0,0 +1,7 @@
1
+ doc
2
+ pkg
3
+ tmp/*
4
+ .DS_Store
5
+ .yardoc
6
+ *.swp
7
+ *~
data/.yardopts CHANGED
@@ -1 +1 @@
1
- --markup markdown --title 'Chars Documentation' --protected --quiet --files ChangeLog.md,LICENSE.txt
1
+ --markup markdown --title 'Chars Documentation' --protected --quiet
@@ -1,3 +1,13 @@
1
+ ### 0.2.2 / 2012-05-28
2
+
3
+ * {Chars::CharSet#initialize} now raises a TypeError when given arguments
4
+ that were neither a `String`, `Integer` or `Enumerable`.
5
+ * Allow {Chars::CharSet#strings_in} to yield results as they are found.
6
+ * Improved the performance of {Chars::CharSet#strings_in} when operating on
7
+ small Strings.
8
+ * Replaced ore-tasks with
9
+ [rubygems-tasks](https://github.com/postmodern/rubygems-tasks#readme).
10
+
1
11
  ### 0.2.1 / 2011-06-22
2
12
 
3
13
  * Added {Chars::CharSet.[]}
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2009-2010 Hal Brodigan
3
+ Copyright (c) 2009-2012 Hal Brodigan
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # Chars
2
2
 
3
- * http://chars.rubyforge.org/
4
- * http://github.com/postmodern/chars/
5
- * Postmodern (postmodern.mod3 at gmail.com)
3
+ * [Source](https://github.com/postmodern/chars#readme)
4
+ * [Issues](https://github.com/postmodern/chars/issues)
5
+ * [Documentation](http://rubydoc.info/gems/chars)
6
+ * [Email](mailto:postmodern.mod3 at gmail.com)
6
7
 
7
8
  ## Description
8
9
 
data/Rakefile CHANGED
@@ -2,13 +2,13 @@ require 'rubygems'
2
2
  require 'rake'
3
3
 
4
4
  begin
5
- gem 'ore-tasks', '~> 0.4'
6
- require 'ore/tasks'
5
+ gem 'rubygems-tasks', '~> 0.1'
6
+ require 'rubygems/tasks'
7
7
 
8
- Ore::Tasks.new
8
+ Gem::Tasks.new
9
9
  rescue LoadError => e
10
- STDERR.puts e.message
11
- STDERR.puts "Run `gem install ore-tasks` to install 'ore/tasks'."
10
+ warn e.message
11
+ warn "Run `gem install rubygems-tasks` to install 'rubygems/tasks'."
12
12
  end
13
13
 
14
14
  begin
@@ -25,7 +25,7 @@ task :test => :spec
25
25
  task :default => :spec
26
26
 
27
27
  begin
28
- gem 'yard', '~> 0.6.0'
28
+ gem 'yard', '~> 0.7'
29
29
  require 'yard'
30
30
 
31
31
  YARD::Rake::YardocTask.new
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__),'..','lib'))
4
+
5
+ require 'chars'
6
+ require 'benchmark'
7
+
8
+ CHARSET = Chars::ALPHA_NUMERIC
9
+ N = 1_000_000
10
+ STRING = ('A' * N) + '!'
11
+ ENUM = (['A', 0x42] * (N / 2)) << '!'
12
+
13
+ Benchmark.bm(12) do |b|
14
+ b.report('String') { CHARSET === STRING }
15
+ b.report('Enumerable') { CHARSET === ENUM }
16
+ end
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__),'..','lib'))
4
+
5
+ require 'chars'
6
+ require 'benchmark'
7
+
8
+ CHARSET = Chars::ALPHA_NUMERIC
9
+ STRING = File.open('/usr/bin/openssl','rb') do |file|
10
+ file.read
11
+ end
12
+
13
+ Benchmark.bm(24) do |b|
14
+ b.report('strings_in') do
15
+ CHARSET.strings_in(STRING) { |offset,string| }
16
+ end
17
+
18
+ (5..20).step(5) do |n|
19
+ b.report("strings_in (length=#{n})") do
20
+ CHARSET.strings_in(STRING, :length => n) { |offset,string| }
21
+ end
22
+ end
23
+ end
@@ -2,126 +2,59 @@
2
2
 
3
3
  require 'yaml'
4
4
 
5
- Gem::Specification.new do |gemspec|
6
- files = if File.directory?('.git')
7
- `git ls-files`.split($/)
8
- elsif File.directory?('.hg')
9
- `hg manifest`.split($/)
10
- elsif File.directory?('.svn')
11
- `svn ls -R`.split($/).select { |path| File.file?(path) }
12
- else
13
- Dir['{**/}{.*,*}'].select { |path| File.file?(path) }
14
- end
5
+ Gem::Specification.new do |gem|
6
+ gemspec = YAML.load_file('gemspec.yml')
15
7
 
16
- filter_files = lambda { |paths|
17
- case paths
18
- when Array
19
- (files & paths)
20
- when String
21
- (files & Dir[paths])
22
- end
23
- }
24
-
25
- version = {
26
- :file => 'lib/chars/version.rb',
27
- :constant => 'Chars::VERSION'
28
- }
29
-
30
- defaults = {
31
- 'name' => File.basename(File.dirname(__FILE__)),
32
- 'files' => files,
33
- 'executables' => filter_files['bin/*'].map { |path| File.basename(path) },
34
- 'test_files' => filter_files['{test/{**/}*_test.rb,spec/{**/}*_spec.rb}'],
35
- 'extra_doc_files' => filter_files['*.{txt,rdoc,md,markdown,tt,textile}'],
36
- }
37
-
38
- metadata = defaults.merge(YAML.load_file('gemspec.yml'))
39
-
40
- gemspec.name = metadata.fetch('name',defaults[:name])
41
- gemspec.version = if metadata['version']
42
- metadata['version']
43
- elsif File.file?(version[:file])
44
- require File.join('.',version[:file])
45
- eval(version[:constant])
46
- end
47
-
48
- gemspec.summary = metadata.fetch('summary',metadata['description'])
49
- gemspec.description = metadata.fetch('description',metadata['summary'])
50
-
51
- case metadata['license']
52
- when Array
53
- gemspec.licenses = metadata['license']
54
- when String
55
- gemspec.license = metadata['license']
56
- end
57
-
58
- case metadata['authors']
59
- when Array
60
- gemspec.authors = metadata['authors']
61
- when String
62
- gemspec.author = metadata['authors']
63
- end
8
+ gem.name = gemspec.fetch('name')
9
+ gem.version = gemspec.fetch('version') do
10
+ lib_dir = File.join(File.dirname(__FILE__),'lib')
11
+ $LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
64
12
 
65
- gemspec.email = metadata['email']
66
- gemspec.homepage = metadata['homepage']
13
+ require 'chars/version'
14
+ Chars::VERSION
15
+ end
67
16
 
68
- case metadata['require_paths']
69
- when Array
70
- gemspec.require_paths = metadata['require_paths']
71
- when String
72
- gemspec.require_path = metadata['require_paths']
73
- end
17
+ gem.summary = gemspec['summary']
18
+ gem.description = gemspec['description']
19
+ gem.licenses = Array(gemspec['license'])
20
+ gem.authors = Array(gemspec['authors'])
21
+ gem.email = gemspec['email']
22
+ gem.homepage = gemspec['homepage']
74
23
 
75
- gemspec.files = filter_files[metadata['files']]
24
+ glob = lambda { |patterns| gem.files & Dir[*patterns] }
76
25
 
77
- gemspec.executables = metadata['executables']
78
- gemspec.extensions = metadata['extensions']
26
+ gem.files = `git ls-files`.split($/)
27
+ gem.files = glob[gemspec['files']] if gemspec['files']
79
28
 
80
- if Gem::VERSION < '1.7.'
81
- gemspec.default_executable = gemspec.executables.first
29
+ gem.executables = gemspec.fetch('executables') do
30
+ glob['bin/*'].map { |path| File.basename(path) }
82
31
  end
32
+ gem.default_executable = gem.executables.first if Gem::VERSION < '1.7.'
83
33
 
84
- gemspec.test_files = filter_files[metadata['test_files']]
85
-
86
- unless gemspec.files.include?('.document')
87
- gemspec.extra_rdoc_files = metadata['extra_doc_files']
88
- end
89
-
90
- gemspec.post_install_message = metadata['post_install_message']
91
- gemspec.requirements = metadata['requirements']
92
-
93
- if gemspec.respond_to?(:required_ruby_version=)
94
- gemspec.required_ruby_version = metadata['required_ruby_version']
95
- end
34
+ gem.extensions = glob[gemspec['extensions'] || 'ext/**/extconf.rb']
35
+ gem.test_files = glob[gemspec['test_files'] || '{test/{**/}*_test.rb']
36
+ gem.extra_rdoc_files = glob[gemspec['extra_doc_files'] || '*.{txt,md}']
96
37
 
97
- if gemspec.respond_to?(:required_rubygems_version=)
98
- gemspec.required_rubygems_version = metadata['required_ruby_version']
99
- end
38
+ gem.require_paths = Array(gemspec.fetch('require_paths') {
39
+ %w[ext lib].select { |dir| File.directory?(dir) }
40
+ })
100
41
 
101
- parse_versions = lambda { |versions|
102
- case versions
103
- when Array
104
- versions.map { |v| v.to_s }
105
- when String
106
- versions.split(/,\s*/)
107
- end
108
- }
42
+ gem.requirements = gemspec['requirements']
43
+ gem.required_ruby_version = gemspec['required_ruby_version']
44
+ gem.required_rubygems_version = gemspec['required_rubygems_version']
45
+ gem.post_install_message = gemspec['post_install_message']
109
46
 
110
- if metadata['dependencies']
111
- metadata['dependencies'].each do |name,versions|
112
- gemspec.add_dependency(name,parse_versions[versions])
113
- end
114
- end
47
+ split = lambda { |string| string.split(/,\s*/) }
115
48
 
116
- if metadata['runtime_dependencies']
117
- metadata['runtime_dependencies'].each do |name,versions|
118
- gemspec.add_runtime_dependency(name,parse_versions[versions])
49
+ if gemspec['dependencies']
50
+ gemspec['dependencies'].each do |name,versions|
51
+ gem.add_dependency(name,split[versions])
119
52
  end
120
53
  end
121
54
 
122
- if metadata['development_dependencies']
123
- metadata['development_dependencies'].each do |name,versions|
124
- gemspec.add_development_dependency(name,parse_versions[versions])
55
+ if gemspec['development_dependencies']
56
+ gemspec['development_dependencies'].each do |name,versions|
57
+ gem.add_development_dependency(name,split[versions])
125
58
  end
126
59
  end
127
60
  end
@@ -5,7 +5,7 @@ description:
5
5
  recognizing text and generating random text from specific character sets.
6
6
 
7
7
  license: MIT
8
- homepage: http://github.com/postmodern/chars
8
+ homepage: https://github.com/postmodern/chars#readme
9
9
  authors: Postmodern
10
10
  email: postmodern.mod3@gmail.com
11
11
  has_yard: true
@@ -13,6 +13,6 @@ has_yard: true
13
13
  required_ruby_version: ">= 1.8.7"
14
14
 
15
15
  development_dependencies:
16
- ore-tasks: ~> 0.4
16
+ rubygems-tasks: ~> 0.1
17
17
  rspec: ~> 2.4
18
- yard: ~> 0.6.1
18
+ yard: ~> 0.7
@@ -9,6 +9,9 @@ module Chars
9
9
  # @param [Array<String, Integer, Enumerable>] arguments
10
10
  # The chars for the CharSet.
11
11
  #
12
+ # @raise [TypeError]
13
+ # One of the arguments was not a {String}, {Integer} or `Enumerable`.
14
+ #
12
15
  def initialize(*arguments)
13
16
  super()
14
17
 
@@ -21,7 +24,7 @@ module Chars
21
24
  when Enumerable
22
25
  subset.each { |char| self << char }
23
26
  else
24
- raise(ArgumentError,"arguments must be a String, Integer or Enumerable")
27
+ raise(TypeError,"arguments must be a String, Integer or Enumerable")
25
28
  end
26
29
  end
27
30
  end
@@ -46,7 +49,7 @@ module Chars
46
49
  # @return [CharSet]
47
50
  # The modified character set.
48
51
  #
49
- # @raise [ArgumentError]
52
+ # @raise [TypeError]
50
53
  # The argument was not a {String} or {Integer}.
51
54
  #
52
55
  # @since 0.2.1
@@ -65,7 +68,7 @@ module Chars
65
68
  when Integer
66
69
  super(other)
67
70
  else
68
- raise(ArgumentError,"can only append Strings and Integers")
71
+ raise(TypeError,"can only append Strings and Integers")
69
72
  end
70
73
  end
71
74
 
@@ -326,23 +329,36 @@ module Chars
326
329
  # sub-strings within the data, or to just return the matched
327
330
  # sub-strings themselves.
328
331
  #
329
- def strings_in(data,options={})
330
- min_length = options.fetch(:length,4)
331
-
332
- return found if data.length < min_length
332
+ # @yield [match,(index)]
333
+ # The given block will be passed every matched sub-string, and the
334
+ # optional index.
335
+ #
336
+ # @yield [String] match
337
+ # A sub-string containing the characters from the character set.
338
+ #
339
+ # @yield [Integer] index
340
+ # The index the sub-string was found at.
341
+ #
342
+ # @return [Array, Hash]
343
+ # If no block is given, an Array or Hash of sub-strings is returned.
344
+ #
345
+ def strings_in(data,options={},&block)
346
+ unless block
347
+ if options[:offsets]
348
+ found = {}
349
+ block = lambda { |offset,substring| found[offset] = substring }
350
+ else
351
+ found = []
352
+ block = lambda { |substring| found << substring }
353
+ end
333
354
 
334
- if options[:offsets]
335
- found = {}
336
- found_substring = lambda { |offset,substring|
337
- found[offset] = substring
338
- }
339
- else
340
- found = []
341
- found_substring = lambda { |offset,substring|
342
- found << substring
343
- }
355
+ strings_in(data,options,&block)
356
+ return found
344
357
  end
345
358
 
359
+ min_length = options.fetch(:length,4)
360
+ return if data.length < min_length
361
+
346
362
  index = 0
347
363
 
348
364
  while index <= (data.length - min_length)
@@ -353,14 +369,20 @@ module Chars
353
369
  sub_index += 1
354
370
  end
355
371
 
356
- found_substring.call(index,data[index...sub_index])
372
+ match = data[index...sub_index]
373
+
374
+ case block.arity
375
+ when 2
376
+ yield match, index
377
+ else
378
+ yield match
379
+ end
380
+
357
381
  index = sub_index
358
382
  else
359
383
  index += 1
360
384
  end
361
385
  end
362
-
363
- return found
364
386
  end
365
387
 
366
388
  #
@@ -385,7 +407,7 @@ module Chars
385
407
  # Compares the bytes within a given string with the bytes of the
386
408
  # character set.
387
409
  #
388
- # @param [String, Enumerable] string
410
+ # @param [String, Enumerable] other
389
411
  # The string to compare with the character set.
390
412
  #
391
413
  # @return [Boolean]
@@ -1,4 +1,4 @@
1
1
  module Chars
2
- # Chars version
3
- VERSION = '0.2.1'
2
+ # chars version
3
+ VERSION = '0.2.2'
4
4
  end
metadata CHANGED
@@ -1,70 +1,85 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: chars
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
4
5
  prerelease:
5
- version: 0.2.1
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Postmodern
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-06-22 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: ore-tasks
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
12
+ date: 2012-05-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rubygems-tasks
16
+ requirement: !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
18
+ requirements:
21
19
  - - ~>
22
- - !ruby/object:Gem::Version
23
- version: "0.4"
20
+ - !ruby/object:Gem::Version
21
+ version: '0.1'
24
22
  type: :development
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: rspec
28
23
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0.1'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
30
33
  none: false
31
- requirements:
34
+ requirements:
32
35
  - - ~>
33
- - !ruby/object:Gem::Version
34
- version: "2.4"
36
+ - !ruby/object:Gem::Version
37
+ version: '2.4'
35
38
  type: :development
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: yard
39
39
  prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '2.4'
46
+ - !ruby/object:Gem::Dependency
47
+ name: yard
48
+ requirement: !ruby/object:Gem::Requirement
41
49
  none: false
42
- requirements:
50
+ requirements:
43
51
  - - ~>
44
- - !ruby/object:Gem::Version
45
- version: 0.6.1
52
+ - !ruby/object:Gem::Version
53
+ version: '0.7'
46
54
  type: :development
47
- version_requirements: *id003
48
- description: Chars is a Ruby library for working with various character sets, recognizing text and generating random text from specific character sets.
49
- email:
50
- - postmodern.mod3@gmail.com
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.7'
62
+ description: Chars is a Ruby library for working with various character sets, recognizing
63
+ text and generating random text from specific character sets.
64
+ email: postmodern.mod3@gmail.com
51
65
  executables: []
52
-
53
66
  extensions: []
54
-
55
- extra_rdoc_files:
56
- - README.md
67
+ extra_rdoc_files:
57
68
  - ChangeLog.md
58
69
  - LICENSE.txt
59
- files:
70
+ - README.md
71
+ files:
60
72
  - .document
61
73
  - .gemspec
74
+ - .gitignore
62
75
  - .rspec
63
76
  - .yardopts
64
77
  - ChangeLog.md
65
78
  - LICENSE.txt
66
79
  - README.md
67
80
  - Rakefile
81
+ - benchmarks/compare.rb
82
+ - benchmarks/strings_in.rb
68
83
  - chars.gemspec
69
84
  - gemspec.yml
70
85
  - lib/chars.rb
@@ -79,35 +94,29 @@ files:
79
94
  - spec/extensions/integer_spec.rb
80
95
  - spec/extensions/string_spec.rb
81
96
  - spec/spec_helper.rb
82
- homepage: http://github.com/postmodern/chars
83
- licenses:
97
+ homepage: https://github.com/postmodern/chars#readme
98
+ licenses:
84
99
  - MIT
85
100
  post_install_message:
86
101
  rdoc_options: []
87
-
88
- require_paths:
102
+ require_paths:
89
103
  - lib
90
- required_ruby_version: !ruby/object:Gem::Requirement
104
+ required_ruby_version: !ruby/object:Gem::Requirement
91
105
  none: false
92
- requirements:
93
- - - ">="
94
- - !ruby/object:Gem::Version
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
95
109
  version: 1.8.7
96
- required_rubygems_version: !ruby/object:Gem::Requirement
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
111
  none: false
98
- requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- version: "0"
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
102
116
  requirements: []
103
-
104
- rubyforge_project: chars
105
- rubygems_version: 1.8.5
117
+ rubyforge_project:
118
+ rubygems_version: 1.8.24
106
119
  signing_key:
107
120
  specification_version: 3
108
121
  summary: A Ruby library for working with various character sets
109
- test_files:
110
- - spec/chars_spec.rb
111
- - spec/char_set_spec.rb
112
- - spec/extensions/integer_spec.rb
113
- - spec/extensions/string_spec.rb
122
+ test_files: []