imitation 0.0.1

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.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+ *.gemspec
21
+
22
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 okitan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,20 @@
1
+ = imitation
2
+
3
+ random input generator for testing
4
+
5
+ == Usage
6
+
7
+ class Data
8
+ extend Imitation
9
+
10
+ AUTHORS = %w[ okitan kuny okitakunio ]
11
+ end
12
+
13
+ Data.author #=> okitan, kuny or okitakunio
14
+ Data.author? #=> okitan, kuny, okitakunio or ''
15
+ Data.authors #=> e.g. %w[ okitan ], %w[ kuny okitakunio ]
16
+
17
+
18
+ == Copyright
19
+
20
+ Copyright (c) 2009 okitan. See LICENSE for details.
@@ -0,0 +1,49 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = 'imitation'
8
+ gem.summary = 'random input generator for testing'
9
+ gem.description = 'sample input generator for testing'
10
+ gem.email = 'okitakunio@gmail.com'
11
+ gem.homepage = 'http://github.com/okitan/imitation'
12
+ gem.authors = ['okitan']
13
+
14
+ gem.add_dependency 'linguistics', '>= 1.0.8'
15
+
16
+ gem.add_development_dependency 'rspec', '>= 1.2.9'
17
+ gem.add_development_dependency 'rr', '>= 0.10.4'
18
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
19
+ end
20
+ Jeweler::GemcutterTasks.new
21
+ rescue LoadError
22
+ puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler'
23
+ end
24
+
25
+ require 'spec/rake/spectask'
26
+ Spec::Rake::SpecTask.new(:spec) do |spec|
27
+ spec.libs << 'lib' << 'spec'
28
+ spec.spec_files = FileList['spec/**/*_spec.rb']
29
+ end
30
+
31
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
32
+ spec.libs << 'lib' << 'spec'
33
+ spec.pattern = 'spec/**/*_spec.rb'
34
+ spec.rcov = true
35
+ end
36
+
37
+ task :spec => :check_dependencies
38
+
39
+ task :default => :spec
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ''
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "imitation #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,23 @@
1
+ class Array
2
+ def rand
3
+ self.at(Kernel.rand(self.size))
4
+ end
5
+
6
+ def rand?
7
+ (self + [ '' ]).rand
8
+ end
9
+
10
+ def subset(count = nil)
11
+ array = self.dup
12
+ if (count ||= Kernel.rand(array.size).next) > array.size / 2
13
+ (array.size - count).times { array.delete_at(Kernel.rand(array.size)) }
14
+ array
15
+ else
16
+ count.times.inject([]) {|result, i| result << array.delete_at(Kernel.rand(array.size)) }
17
+ end
18
+ end
19
+
20
+ def subset?
21
+ (i = Kernel.rand(self.size.next)) == self.size ? [] : subset(i.next)
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ class String
2
+ # I'm wondering the interface of linguistic, but I don't wanna use ActiveSupport
3
+ # 'box'.en.plural #=> 'boxes'
4
+ # 'box'.en.plural_noun #=> 'boxes'
5
+ # 'boxes'.en.plural #=> 'box'
6
+ # 'boxes'.en.plural_noun #=> 'boxess'
7
+ # 'carp'.en.plural #=> 'carp'
8
+ # 'carp'.en.plural_noun #=> 'carp'
9
+ # See spec.
10
+ def plural?
11
+ if self == self.en.plural # e.g. carp
12
+ true
13
+ else
14
+ self.en.plural == self.en.plural_noun ? false : true
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,26 @@
1
+ require 'linguistics'
2
+ Linguistics::use(:en)
3
+
4
+ %w[ array string ].each {|f| require "core_ext/#{f}" }
5
+
6
+ module Imitation
7
+ def method_missing(name, *args, &block)
8
+ name_s = name.to_s
9
+ naked = name_s.sub(/\?$/, '')
10
+ plural = naked.plural?
11
+ pluraled = plural ? naked : naked.en.plural
12
+ upcased = pluraled.upcase
13
+
14
+ if const_defined?(upcased)
15
+ method = (plural and pluraled != pluraled.en.plural) ? 'subset' : 'rand' # 'carp' results rand
16
+ module_eval <<-DEF, __FILE__, __LINE__
17
+ def self.#{name_s}
18
+ #{upcased}.#{method}#{'?' unless name_s == naked}
19
+ end
20
+ DEF
21
+ __send__(name)
22
+ else
23
+ raise NameError, "#{upcased} is not defined for #{name_s}"
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ require File.join(File.dirname(__FILE__), %w[ .. spec_helper])
2
+ =begin
3
+ describe 'Array#rand' do
4
+ subject { Array.new }
5
+
6
+ it 'should call [] at random position' do
7
+ mock(Kernel).rand(subject.size) { @num = stub! }
8
+ mock(subject).at(@num)
9
+
10
+ subject.rand
11
+ end
12
+ end
13
+ =end
@@ -0,0 +1,15 @@
1
+ require File.join(File.dirname(__FILE__), %w[ .. spec_helper])
2
+
3
+ {
4
+ true => %w[ boxes indices carp ],
5
+ false => %w[ box index ]
6
+ }.each do |result, words|
7
+ words.each do |word|
8
+ describe "#{word}.plural?" do
9
+ subject { word.plural? }
10
+
11
+ it { should == result }
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,63 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe 'Class which extends Imitation and defines AUTHORS' do
4
+ before :all do
5
+ instance_eval do
6
+ class Data
7
+ extend Imitation
8
+ AUTHORS = []
9
+ end
10
+ end
11
+ end
12
+
13
+ it 'should respond author with AUTHORS.rand' do
14
+ mock(Data::AUTHORS).rand
15
+ Data.author
16
+ end
17
+
18
+ it 'should respond author? with AUTHORS.rand?' do
19
+ mock(Data::AUTHORS).rand?
20
+ Data.author?
21
+ end
22
+
23
+ it 'should respond authors with AUTHORS.subset' do
24
+ mock(Data::AUTHORS).subset
25
+ Data.authors
26
+ end
27
+
28
+ it 'should respond authors? with AUTHORS.subset' do
29
+ mock(Data::AUTHORS).subset?
30
+ Data.authors?
31
+ end
32
+
33
+ it 'should raise NameError when other methods called' do
34
+ lambda { Data.hoge }.should raise_error(NameError)
35
+ end
36
+ end
37
+
38
+ describe 'Class which extend Imitation and defines CARP(the same form both in the singular and in the plural)' do
39
+ before :all do
40
+ instance_eval do
41
+ class Data
42
+ extend Imitation
43
+ CARP = []
44
+ end
45
+ end
46
+ end
47
+
48
+ it 'should respond carp with CARP.subset and not CARP.rand' do
49
+ mock(Data::CARP).rand
50
+ do_not_allow(Data::CARP).subset
51
+ Data.carp
52
+ end
53
+
54
+ it 'should respond carp? with CARP.rand?' do
55
+ mock(Data::CARP).rand?
56
+ do_not_allow(Data::CARP).subset?
57
+ Data.carp?
58
+ end
59
+
60
+ it 'should raise NameError when other methods called' do
61
+ lambda { Data.hoge }.should raise_error(NameError)
62
+ end
63
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,12 @@
1
+ require 'spec'
2
+ begin
3
+ require 'rr'
4
+ rescue LoadError
5
+ require 'rubygems'
6
+ require 'rr'
7
+ end
8
+ require File.join(File.dirname(__FILE__), %w[ .. lib imitation])
9
+
10
+ Spec::Runner.configure do |config|
11
+ config.mock_with :rr
12
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: imitation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - okitan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-07 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: linguistics
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.0.8
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.9
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: rr
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.10.4
44
+ version:
45
+ description: sample input generator for testing
46
+ email: okitakunio@gmail.com
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - LICENSE
53
+ - README.rdoc
54
+ files:
55
+ - .document
56
+ - .gitignore
57
+ - LICENSE
58
+ - README.rdoc
59
+ - Rakefile
60
+ - VERSION
61
+ - lib/core_ext/array.rb
62
+ - lib/core_ext/string.rb
63
+ - lib/imitation.rb
64
+ - spec/core_ext/string_spec.rb
65
+ - spec/imitation_spec.rb
66
+ - spec/spec.opts
67
+ - spec/spec_helper.rb
68
+ has_rdoc: true
69
+ homepage: http://github.com/okitan/imitation
70
+ licenses: []
71
+
72
+ post_install_message:
73
+ rdoc_options:
74
+ - --charset=UTF-8
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:
92
+ rubygems_version: 1.3.5
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: random input generator for testing
96
+ test_files:
97
+ - spec/spec_helper.rb
98
+ - spec/imitation_spec.rb
99
+ - spec/core_ext/array_spec.rb
100
+ - spec/core_ext/string_spec.rb