cmd_matcher 0.0.1 → 0.0.2

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.
Files changed (4) hide show
  1. data/README +22 -1
  2. data/Rakefile +4 -4
  3. data/lib/cmd_matcher.rb +2 -15
  4. metadata +7 -7
data/README CHANGED
@@ -1,3 +1,24 @@
1
1
  == cmd_matcher
2
+ command line response to hash
3
+ usage:
2
4
 
3
- You should document your project here.
5
+ cm = CmdMatcher.new
6
+ cm.has_one "++++++++++++++++++++++++++++++++++"
7
+ cm.has_one "sn type id"
8
+ cm.has_one "++++++++++++++++++++++++++++++++++"
9
+ cm.has_many /(\d+)\s+(trunk|access)\s+(\d+)/, :names => [:sn, :type, :id]
10
+ cm.has "++++++++++++++++++++++++++++++++++", :at_most => 1
11
+ cm.has_one /total\s*(\d+)/, :names => [:total]
12
+
13
+ cm.match(%Q{++++++++++++++++++++++++++++++++++
14
+ sn type id
15
+ ++++++++++++++++++++++++++++++++++
16
+ 1 trunk 100
17
+ 2 access 200
18
+ ++++++++++++++++++++++++++++++++++
19
+ total 2
20
+ })
21
+ puts cm.matches[:total]
22
+ puts cm.matches[:type][0]
23
+ puts cm.matches[:type][1]
24
+
data/Rakefile CHANGED
@@ -13,13 +13,13 @@ require 'spec/rake/spectask'
13
13
 
14
14
  spec = Gem::Specification.new do |s|
15
15
  s.name = 'cmd_matcher'
16
- s.version = '0.0.1'
16
+ s.version = '0.0.2'
17
17
  s.has_rdoc = true
18
18
  s.extra_rdoc_files = ['README', 'LICENSE']
19
- s.summary = 'command line matcher'
19
+ s.summary = 'command line response to hash'
20
20
  s.description = s.summary
21
- s.author = ''
22
- s.email = ''
21
+ s.author = 'YuZhenpin'
22
+ s.email = 'yuzhenpin@126.com'
23
23
  # s.executables = ['your_executable_here']
24
24
  s.files = %w(LICENSE README Rakefile) + Dir.glob("{bin,lib,spec}/**/*")
25
25
  s.require_path = "lib"
data/lib/cmd_matcher.rb CHANGED
@@ -40,7 +40,6 @@ class CmdMatcher
40
40
  lines.shift
41
41
  times += 1
42
42
  else
43
- puts "times=#{times}"
44
43
  if opt[:at_least] && opt[:at_least] > times
45
44
  return false
46
45
  end
@@ -67,25 +66,23 @@ class CmdMatcher
67
66
 
68
67
  def line_regex(lines, expect, opt = {})
69
68
  line = lines[0]
70
- puts "line=#{line}"
71
69
  line_matcher = LineMatcher.new(expect, opt)
72
70
  if line_matcher.match(line)
73
71
  line_matcher.append_to(@matches)
74
72
  return true
75
73
  else
76
- puts "unequal: <expect>#{expect},\n <but got>#{line}"
74
+ puts "<expect>#{expect},\n <but got>#{line}" if $DEBUG
77
75
  return false
78
76
  end
79
77
  end
80
78
 
81
79
  def line_equal(lines, expect, opt = {})
82
80
  line = lines[0]
83
- puts "line=#{line}"
84
81
  line_equaler = LineEqualer.new(expect, opt)
85
82
  if line_equaler.match(line)
86
83
  return true
87
84
  else
88
- puts "unequal: <expect>#{expect},\n <but got>#{line}"
85
+ puts "<expect>#{expect},\n <but got>#{line}" if $DEBUG
89
86
  return false
90
87
  end
91
88
  end
@@ -133,14 +130,4 @@ class CmdMatcher
133
130
  @matcher.strip == line.strip
134
131
  end
135
132
  end
136
- end
137
-
138
- if __FILE__ == $0
139
- cm = CmdMatcher.new
140
- ao.reply :has_one => "++++++++++++++++++++++++++++++++++"
141
- ao.reply :has_one => "sn type id"
142
- ao.reply :has_one => "++++++++++++++++++++++++++++++++++"
143
- ao.reply :has_many => /(\d)\s*(trunk|access)(\d+)/, :names => [:sn, :type, :id]
144
- ao.reply :has => "++++++++++++++++++++++++++++++++++", :at_least => 1
145
- ao.reply :has => "++++++++++++++++++++++++++++++++++", :at_most => 1
146
133
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cmd_matcher
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
- - ""
13
+ - YuZhenpin
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
@@ -18,8 +18,8 @@ cert_chain: []
18
18
  date: 2012-04-30 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
- description: command line matcher
22
- email: ""
21
+ description: command line response to hash
22
+ email: yuzhenpin@126.com
23
23
  executables: []
24
24
 
25
25
  extensions: []
@@ -66,6 +66,6 @@ rubyforge_project:
66
66
  rubygems_version: 1.8.22
67
67
  signing_key:
68
68
  specification_version: 3
69
- summary: command line matcher
69
+ summary: command line response to hash
70
70
  test_files: []
71
71