ghaki-match 2011.12.04.1 → 2011.12.04.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.
@@ -5,10 +5,10 @@ module Parser #:nodoc:
5
5
  # Matches against paired regular expressions and returned values.
6
6
  class Base
7
7
 
8
- attr_accessor :lookups, :default_value
8
+ attr_accessor :match_lookup, :default_value
9
9
 
10
- def initialize pairs={}, opts={}
11
- @lookups = pairs
10
+ def initialize opts={}
11
+ @match_lookup = opts[:match_lookup] || {}
12
12
  @default_value = opts[:default_value]
13
13
  add_words( opts[:match_words] ) if opts.has_key?(:match_words)
14
14
  end
@@ -25,7 +25,7 @@ class Base
25
25
  def add_words pairs
26
26
  pairs.each_pair do |val,keyz|
27
27
  keyz.each do |key|
28
- @lookups[ %r{\b#{key}\b}i ] = val
28
+ @match_lookup[ %r{\A#{key}\z}i ] = val
29
29
  end
30
30
  end
31
31
  end
@@ -33,7 +33,7 @@ class Base
33
33
  # Matches lines against regexp keys returning paired value.
34
34
  # - Yields on not found or returns default value.
35
35
  def match_lines lines, opts={}
36
- @lookups.each_pair do |rx_curr,ret_val|
36
+ @match_lookup.each_pair do |rx_curr,ret_val|
37
37
  lines.each do |text|
38
38
  return ret_val if text =~ rx_curr
39
39
  end
@@ -50,7 +50,7 @@ class Base
50
50
  # Matches string against regexp keys returning paired value.
51
51
  # - Yields on not found or returns default value.
52
52
  def match_text text, opts={}
53
- @lookups.each_pair do |rx_curr,ret_val|
53
+ @match_lookup.each_pair do |rx_curr,ret_val|
54
54
  return ret_val if text =~ rx_curr
55
55
  end
56
56
  if block_given?
@@ -17,7 +17,7 @@ class Boolean < Base
17
17
  @boolean_lookup || []
18
18
  end
19
19
 
20
- def initialize opts={}; super( {}, opts )
20
+ def initialize opts={}; super opts
21
21
  opts_boolean opts
22
22
  end
23
23
 
@@ -2,40 +2,74 @@ require 'ghaki/match/parser/base'
2
2
 
3
3
  module Ghaki module Match module Parser module Base_Testing
4
4
  describe Base do
5
- FIND_KEY = 'FOUND'
6
- FIND_VAL = 'RETURNED'
7
- GOOD_TEXT = 'SHOULD BE FOUND BY PARSER'
5
+ EXACT_KEY = 'FOUND'
6
+ EXACT_VAL = 'EXACT-RETURNED'
7
+ EXACT_TEXT = 'FounD'
8
+ EXACT_FAIL = 'THIS FOUND NOW'
9
+ EXACT_WORDS = { EXACT_VAL => [EXACT_KEY] }
10
+
11
+ BOUND_KEY = 'HERE'
12
+ BOUND_VAL = 'BOUND-RETURNED'
13
+ BOUND_TEXT = 'LOOK HERE NOW'
14
+ BOUND_LOOKUP = { %r{\b#{BOUND_KEY}\b}i => BOUND_VAL }
15
+
8
16
  MISS_TEXT = 'INVALID'
9
17
  MISS_DEF = 'PASS_BACK'
10
18
 
11
- subject do
12
- Base.new({
13
- %r{\b#{FIND_KEY}\b} => FIND_VAL,
14
- })
15
- end
16
-
17
19
  describe '#initialize' do
20
+
21
+ context 'using no options' do
22
+ it 'has empty match lookups' do
23
+ Base.new.match_lookup.should be_empty
24
+ end
25
+ end
26
+
27
+ context 'using option :match_lookup' do
28
+ it 'accepts' do
29
+ @subj = Base.new( :match_lookup => BOUND_LOOKUP )
30
+ @subj.match_lookup.should_not be_empty
31
+ @subj.match_text(BOUND_TEXT).should == BOUND_VAL
32
+ end
33
+ end
34
+
18
35
  context 'using option :match_words' do
19
36
  it 'accepts' do
20
- @subj = Base.new( :match_words => { FIND_VAL => [FIND_KEY] } )
21
- subject.match_text(GOOD_TEXT).should == FIND_VAL
37
+ @subj = Base.new( :match_words => EXACT_WORDS )
38
+ @subj.match_lookup.should_not be_empty
39
+ @subj.match_text(EXACT_TEXT).should == EXACT_VAL
22
40
  end
23
41
  end
42
+
24
43
  end
25
44
 
45
+ subject { Base.new }
46
+
47
+ it { should respond_to :match_lookup }
48
+ it { should respond_to :match_lookup= }
49
+ it { should respond_to :default_value }
50
+ it { should respond_to :default_value= }
51
+
26
52
  describe '#add_words' do
27
- subject { Base.new }
28
- it 'generates match pairs' do
29
- subject.add_words FIND_VAL => [FIND_KEY]
30
- subject.match_text(GOOD_TEXT).should == FIND_VAL
53
+ before(:each) do
54
+ subject.add_words EXACT_VAL => [EXACT_KEY]
55
+ end
56
+ it 'matches against exact text' do
57
+ subject.match_text(EXACT_TEXT).should == EXACT_VAL
58
+ end
59
+ it 'does not match against boundary' do
60
+ subject.match_text(EXACT_FAIL).should be_nil
31
61
  end
32
62
  end
33
63
 
34
64
  describe '#match_text' do
35
65
 
66
+ before(:each) do
67
+ subject.match_lookup = BOUND_LOOKUP
68
+ end
69
+
36
70
  context 'when matched' do
37
71
  it 'passes specified value' do
38
- subject.match_text(GOOD_TEXT).should == FIND_VAL
72
+ subject.match_text(BOUND_TEXT).should == BOUND_VAL
39
73
  end
40
74
  end
41
75
 
@@ -66,9 +100,13 @@ describe Base do
66
100
 
67
101
  describe '#match_lines' do
68
102
 
103
+ before(:each) do
104
+ subject.match_lookup = BOUND_LOOKUP
105
+ end
106
+
69
107
  context 'when matched' do
70
108
  it 'should match' do
71
- subject.match_lines([GOOD_TEXT]).should == FIND_VAL
109
+ subject.match_lines([BOUND_TEXT]).should == BOUND_VAL
72
110
  end
73
111
  end
74
112
 
@@ -4,9 +4,13 @@ module Ghaki module Match module Parser module Boolean_Testing
4
4
  describe Boolean do
5
5
 
6
6
  FIELDS_EXP = ['EXPECTED']
7
+ FIELD_HAVE = FIELDS_EXP.first
7
8
  EXTRA_KEY = 'ZAP'
8
- EXTRA_TEXT = 'ZIP ZAP ZOOM'
9
+ EXTRA_TEXT = EXTRA_KEY.downcase
9
10
 
11
+ subject { Boolean.new }
12
+
13
+ it { should be_kind_of(Parser::Base) }
10
14
  it { should respond_to :boolean_lookup }
11
15
  it { should respond_to :boolean_lookup= }
12
16
 
@@ -26,11 +30,11 @@ describe Boolean do
26
30
  context 'using option :skip_boolean_defaults' do
27
31
  it 'ignores defaults when specified' do
28
32
  @subj = Boolean.new( :skip_boolean_defaults => true )
29
- @subj.lookups.should be_empty
33
+ @subj.match_lookup.should be_empty
30
34
  end
31
35
  it 'imports defaults when missing' do
32
36
  @subj = Boolean.new
33
- @subj.lookups.should_not be_empty
37
+ @subj.match_lookup.should_not be_empty
34
38
  end
35
39
  end
36
40
 
@@ -52,8 +56,6 @@ describe Boolean do
52
56
 
53
57
  describe '#parse_value' do
54
58
 
55
- subject { Boolean.new }
56
-
57
59
  context 'when unmatched' do
58
60
  let(:text) { 'INVALID' }
59
61
  it 'passes through original value' do
@@ -90,7 +92,7 @@ describe Boolean do
90
92
 
91
93
  context 'with present field' do
92
94
 
93
- let(:field) { FIELDS_EXP.first }
95
+ let(:field) { FIELD_HAVE }
94
96
 
95
97
  context 'when unmatched' do
96
98
  let(:text) { 'NOT_FOUND' }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ghaki-match
3
3
  version: !ruby/object:Gem::Version
4
- version: 2011.12.04.1
4
+ version: 2011.12.04.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-12-04 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ghaki-bool
16
- requirement: &82877040 !ruby/object:Gem::Requirement
16
+ requirement: &79907590 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2011.11.29.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *82877040
24
+ version_requirements: *79907590
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &82876800 !ruby/object:Gem::Requirement
27
+ requirement: &79907320 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.4.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *82876800
35
+ version_requirements: *79907320
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rdoc
38
- requirement: &82876570 !ruby/object:Gem::Requirement
38
+ requirement: &79907030 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 3.9.4
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *82876570
46
+ version_requirements: *79907030
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: mocha
49
- requirement: &82876330 !ruby/object:Gem::Requirement
49
+ requirement: &79906760 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: 0.9.12
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *82876330
57
+ version_requirements: *79906760
58
58
  description: Collection of helpers for regular expression helpers.
59
59
  email: gerald@kalafut.org
60
60
  executables: []