cmd-matcher 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +3 -0
- data/README +3 -0
- data/Rakefile +51 -0
- data/lib/cmd_matcher.rb +58 -0
- data/spec/line_matcher_spec.rb +17 -0
- metadata +70 -0
data/LICENSE
ADDED
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#
|
2
|
+
# To change this template, choose Tools | Templates
|
3
|
+
# and open the template in the editor.
|
4
|
+
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'rake'
|
8
|
+
require 'rake/clean'
|
9
|
+
require 'rake/gempackagetask'
|
10
|
+
require 'rake/rdoctask'
|
11
|
+
require 'rake/testtask'
|
12
|
+
require 'spec/rake/spectask'
|
13
|
+
|
14
|
+
spec = Gem::Specification.new do |s|
|
15
|
+
s.name = 'cmd-matcher'
|
16
|
+
s.version = '0.0.1'
|
17
|
+
s.has_rdoc = true
|
18
|
+
s.extra_rdoc_files = ['README', 'LICENSE']
|
19
|
+
s.summary = 'Your summary here'
|
20
|
+
s.description = s.summary
|
21
|
+
s.author = ''
|
22
|
+
s.email = ''
|
23
|
+
# s.executables = ['your_executable_here']
|
24
|
+
s.files = %w(LICENSE README Rakefile) + Dir.glob("{bin,lib,spec}/**/*")
|
25
|
+
s.require_path = "lib"
|
26
|
+
s.bindir = "bin"
|
27
|
+
end
|
28
|
+
|
29
|
+
Rake::GemPackageTask.new(spec) do |p|
|
30
|
+
p.gem_spec = spec
|
31
|
+
p.need_tar = true
|
32
|
+
p.need_zip = true
|
33
|
+
end
|
34
|
+
|
35
|
+
Rake::RDocTask.new do |rdoc|
|
36
|
+
files =['README', 'LICENSE', 'lib/**/*.rb']
|
37
|
+
rdoc.rdoc_files.add(files)
|
38
|
+
rdoc.main = "README" # page to start on
|
39
|
+
rdoc.title = "cmd-matcher Docs"
|
40
|
+
rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
|
41
|
+
rdoc.options << '--line-numbers'
|
42
|
+
end
|
43
|
+
|
44
|
+
Rake::TestTask.new do |t|
|
45
|
+
t.test_files = FileList['test/**/*.rb']
|
46
|
+
end
|
47
|
+
|
48
|
+
Spec::Rake::SpecTask.new do |t|
|
49
|
+
t.spec_files = FileList['spec/**/*.rb']
|
50
|
+
t.libs << Dir["lib"]
|
51
|
+
end
|
data/lib/cmd_matcher.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
class CmdMatcher
|
2
|
+
def initialize
|
3
|
+
@matchers = []
|
4
|
+
end
|
5
|
+
|
6
|
+
def has(line, opt = {})
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
def head(line, opt = {})
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
def has_one(line, opt = {})
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def has_many(line, opt = {})
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def match(prompts)
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
class LineMatcher
|
27
|
+
attr_reader :matches
|
28
|
+
def initialize(matcher, opt = {})
|
29
|
+
@names = opt[:names] || []
|
30
|
+
@matcher = matcher
|
31
|
+
@matches = nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def match(line)
|
35
|
+
m = line.match(@matcher)
|
36
|
+
return false unless m
|
37
|
+
@matches = {}
|
38
|
+
@names.each_with_index {|name, index|
|
39
|
+
@matches[name] = m[index + 1]
|
40
|
+
}
|
41
|
+
return true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class LineEqualer < LineMatcher
|
46
|
+
def match(line)
|
47
|
+
@matcher.strip == line.strip
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
cm = CmdMatcher.new
|
53
|
+
ao.reply :head => "++++++++++++++++++++++++++++++++++"
|
54
|
+
ao.reply :has_one => "sn type id"
|
55
|
+
ao.reply :has_one => "++++++++++++++++++++++++++++++++++"
|
56
|
+
ao.reply :has_many => /(\d)\s*(trunk|access)(\d+)/, :name => [:sn, :type, :id]
|
57
|
+
ao.reply :has => "++++++++++++++++++++++++++++++++++", :at_last => 1
|
58
|
+
ao.reply :has => "++++++++++++++++++++++++++++++++++", :at_most => 1
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# To change this template, choose Tools | Templates
|
2
|
+
# and open the template in the editor.
|
3
|
+
|
4
|
+
$LOAD_PATH << 'I:\RailsInstaller\Ruby1.8.7\lib\ruby\gems\1.8\gems\cmd-matcher\lib'
|
5
|
+
|
6
|
+
require 'cmd_matcher'
|
7
|
+
|
8
|
+
describe LineMatcher do
|
9
|
+
before(:each) do
|
10
|
+
@line_matcher = LineMatcher.new
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should desc" do
|
14
|
+
# TODO
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cmd-matcher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- ""
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-04-30 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Your summary here
|
22
|
+
email: ""
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- README
|
29
|
+
- LICENSE
|
30
|
+
files:
|
31
|
+
- LICENSE
|
32
|
+
- README
|
33
|
+
- Rakefile
|
34
|
+
- lib/cmd_matcher.rb
|
35
|
+
- spec/line_matcher_spec.rb
|
36
|
+
homepage:
|
37
|
+
licenses: []
|
38
|
+
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
hash: 3
|
50
|
+
segments:
|
51
|
+
- 0
|
52
|
+
version: "0"
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.8.22
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: Your summary here
|
69
|
+
test_files: []
|
70
|
+
|