ghaki-match 2011.11.30.1 → 2011.12.04.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,19 +12,19 @@ module AutoBoolean
12
12
  @auto_boolean_matcher ||= Ghaki::Match::Parser::Boolean.new
13
13
  end
14
14
 
15
- def auto_boolean_fields
16
- auto_boolean_matcher.boolean_fields
15
+ def boolean_lookup
16
+ auto_boolean_matcher.boolean_lookup
17
17
  end
18
18
 
19
- def auto_boolean_fields= val
20
- auto_boolean_matcher.boolean_fields = val
19
+ def boolean_lookup= val
20
+ auto_boolean_matcher.boolean_lookup= val
21
21
  end
22
22
 
23
- def auto_boolean_value val, opts={}, &block
23
+ def boolean_value val, opts={}, &block
24
24
  auto_boolean_matcher.parse_value( val, opts, &block )
25
25
  end
26
26
 
27
- def auto_boolean_field key, val, opts={}, &block
27
+ def boolean_field key, val, opts={}, &block
28
28
  auto_boolean_matcher.parse_field( key, val, opts, &block )
29
29
  end
30
30
 
@@ -7,15 +7,15 @@ module Mixin #:nodoc:
7
7
  module AutoRename
8
8
  extend Ghaki::Bool::Accessors
9
9
 
10
- bool_accessor :auto_rename_to_token
11
- attr_writer :auto_rename_fields
10
+ bool_accessor :auto_tokenize
11
+ attr_writer :field_renames
12
12
 
13
- def auto_rename_fields
14
- @auto_rename_fields || {}
13
+ def field_renames
14
+ @field_renames || {}
15
15
  end
16
16
 
17
17
  # Converts 'HTTP Compression' into :http_compression
18
- def auto_field_name key
18
+ def format_field key
19
19
  key.downcase.gsub(%r{[^A-Z0-9]+}xoi,' ').strip.gsub(' ','_')
20
20
  end
21
21
 
@@ -29,11 +29,11 @@ module AutoRename
29
29
  # - if the rename table exists, and does NOT have an entry
30
30
  # - return the string
31
31
 
32
- def auto_rename_field dirty_key, opts={}
33
- do_token = opts[:auto_rename_to_token]
34
- do_token = self.auto_rename_to_token? if do_token.nil?
35
- to_field = opts[:auto_rename_fields] || self.auto_rename_fields
36
- clean_key = auto_field_name(dirty_key)
32
+ def rename_field dirty_key, opts={}
33
+ do_token = opts[:auto_tokenize]
34
+ do_token = self.auto_tokenize? if do_token.nil?
35
+ to_field = opts[:field_renames] || self.field_renames
36
+ clean_key = format_field(dirty_key)
37
37
  field_key = to_field[clean_key]
38
38
  field_key = do_token if field_key.nil? and (not do_token.nil?)
39
39
  case field_key
@@ -11,14 +11,18 @@ class Boolean < Base
11
11
  false => %w{ FALSE NO OFF DISABLED },
12
12
  }
13
13
 
14
- attr_accessor :boolean_fields
14
+ attr_writer :boolean_lookup
15
+
16
+ def boolean_lookup
17
+ @boolean_lookup || []
18
+ end
15
19
 
16
20
  def initialize opts={}; super( {}, opts )
17
21
  opts_boolean opts
18
22
  end
19
23
 
20
24
  def opts_boolean opts
21
- @boolean_fields = opts[:boolean_fields] || []
25
+ @boolean_lookup = opts[:boolean_lookup]
22
26
  add_trues( opts[:boolean_trues ] ) unless opts[:boolean_trues].nil?
23
27
  add_falses( opts[:boolean_falses] ) unless opts[:boolean_falses].nil?
24
28
  add_words( DEFAULT_VALUES ) unless opts[:skip_boolean_defaults]
@@ -40,7 +44,8 @@ class Boolean < Base
40
44
 
41
45
  # Check whether key is a known boolean field, if so, get truthiness.
42
46
  def parse_field key, val, opts={}, &block
43
- if @boolean_fields.member?(key)
47
+ looky = opts[:boolean_lookup] || self.boolean_lookup
48
+ if looky.member?(key)
44
49
  parse_value( val, opts, &block )
45
50
  else
46
51
  val
@@ -28,56 +28,54 @@ describe AutoBoolean do
28
28
  end
29
29
  end
30
30
 
31
- describe '#auto_boolean_fields' do
31
+ describe '#boolean_lookup' do
32
32
  it 'defaults to empty list' do
33
- subject.auto_boolean_fields.should be_empty
33
+ subject.boolean_lookup.should be_empty
34
34
  end
35
35
  it 'returns truthiness when field is present' do
36
- subject.auto_boolean_fields = FIELDS_EXP
37
- subject.auto_boolean_fields.should == FIELDS_EXP
38
- subject.auto_boolean_field( GOOD_KEY, GOOD_TRUE ).should be_true
36
+ subject.boolean_lookup = FIELDS_EXP
37
+ subject.boolean_field( GOOD_KEY, GOOD_TRUE ).should be_true
39
38
  end
40
39
  it 'returns orginal when field is missing' do
41
- subject.auto_boolean_fields = FIELDS_EXP
42
- subject.auto_boolean_fields.should == FIELDS_EXP
43
- subject.auto_boolean_field( MISS_KEY, GOOD_TRUE ).should == GOOD_TRUE
40
+ subject.boolean_lookup = FIELDS_EXP
41
+ subject.boolean_field( MISS_KEY, GOOD_TRUE ).should == GOOD_TRUE
44
42
  end
45
43
  end
46
44
 
47
- describe '#auto_boolean_value' do
45
+ describe '#boolean_value' do
48
46
 
49
47
  context 'using defaults' do
50
48
  context 'with known values' do
51
49
  Parser::Boolean::DEFAULT_VALUES[true].each do |item|
52
50
  it "returns true for: #{item}" do
53
- subject.auto_boolean_value(item).should be_true
51
+ subject.boolean_value(item).should be_true
54
52
  end
55
53
  end
56
54
  end
57
55
  Parser::Boolean::DEFAULT_VALUES[false].each do |item|
58
56
  it "returns false for: #{item}" do
59
- subject.auto_boolean_value(item).should be_false
57
+ subject.boolean_value(item).should be_false
60
58
  end
61
59
  end
62
60
  end
63
61
  context 'with unknown values' do
64
62
  it 'returns original value' do
65
- subject.auto_boolean_value(MISS_VAL).should == MISS_VAL
63
+ subject.boolean_value(MISS_VAL).should == MISS_VAL
66
64
  end
67
65
  end
68
66
 
69
67
  end
70
68
 
71
- describe '#auto_boolean_field' do
69
+ describe '#boolean_field' do
72
70
  context 'with present field' do
73
71
  it 'converts value to boolean' do
74
- subject.auto_boolean_fields = FIELDS_EXP
75
- subject.auto_boolean_field(GOOD_KEY,GOOD_TRUE).should be_true
72
+ subject.boolean_lookup = FIELDS_EXP
73
+ subject.boolean_field(GOOD_KEY,GOOD_TRUE).should be_true
76
74
  end
77
75
  end
78
76
  context 'with invalid field' do
79
77
  it 'returns original value' do
80
- subject.auto_boolean_field(MISS_KEY,MISS_VAL).should == MISS_VAL
78
+ subject.boolean_field(MISS_KEY,MISS_VAL).should == MISS_VAL
81
79
  end
82
80
  end
83
81
  end
@@ -22,32 +22,32 @@ describe AutoRename do
22
22
  end
23
23
  subject { @subj }
24
24
 
25
- it { should respond_to :auto_rename_to_token? }
26
- it { should respond_to :auto_rename_to_token! }
25
+ it { should respond_to :auto_tokenize? }
26
+ it { should respond_to :auto_tokenize! }
27
27
 
28
- it { should respond_to :auto_rename_fields= }
29
- describe '#auto_rename_fields' do
28
+ it { should respond_to :field_renames= }
29
+ describe '#field_renames' do
30
30
  it 'defaults empty hash' do
31
- subject.auto_rename_fields.should == {}
31
+ subject.field_renames.should == {}
32
32
  end
33
33
  it 'returns set value' do
34
34
  thing = { 'zip' => 'zap' }
35
- subject.auto_rename_fields = thing
36
- subject.auto_rename_fields.should == thing
35
+ subject.field_renames = thing
36
+ subject.field_renames.should == thing
37
37
  end
38
38
  end
39
39
 
40
- describe '#auto_field_name' do
40
+ describe '#format_field' do
41
41
  FIELD_CLEANUP_EXAMPLES.each_pair do |reason,examples|
42
42
  it reason do
43
43
  examples.each_pair do |key,val|
44
- subject.auto_field_name(key).should == val
44
+ subject.format_field(key).should == val
45
45
  end
46
46
  end
47
47
  end
48
48
  end
49
49
 
50
- describe '#auto_rename_field' do
50
+ describe '#rename_field' do
51
51
 
52
52
  ARF_RULES = {
53
53
  'phasellus_tortor_elementum' => true, # clean and token
@@ -68,14 +68,14 @@ describe AutoRename do
68
68
  }
69
69
 
70
70
  before(:each) do
71
- subject.auto_rename_fields = ARF_RULES
71
+ subject.field_renames = ARF_RULES
72
72
  end
73
73
 
74
74
  context 'with matched' do
75
75
  ARF_EXPECTED.each_pair do |reason,examples|
76
76
  it "#{reason} by rule" do
77
77
  examples.each_pair do |get,put|
78
- subject.auto_rename_field(get).should == put
78
+ subject.rename_field(get).should == put
79
79
  end
80
80
  end
81
81
  end
@@ -86,39 +86,39 @@ describe AutoRename do
86
86
  let(:put_token) { :unknown }
87
87
  let(:put_clean) { 'unknown' }
88
88
 
89
- context 'using set :auto_rename_to_token' do
89
+ context 'using set :auto_tokenize' do
90
90
 
91
91
  it 'translates unknown into Symbol' do
92
- subject.auto_rename_to_token! true
93
- subject.auto_rename_field(get_field).should == put_token
92
+ subject.auto_tokenize! true
93
+ subject.rename_field(get_field).should == put_token
94
94
  end
95
95
 
96
96
  it 'translates unknown into String' do
97
- subject.auto_rename_to_token! false
98
- subject.auto_rename_field(get_field).should == put_clean
97
+ subject.auto_tokenize! false
98
+ subject.rename_field(get_field).should == put_clean
99
99
  end
100
100
 
101
101
  it 'fails when not set' do
102
102
  lambda do
103
- subject.auto_rename_field('missing')
103
+ subject.rename_field('missing')
104
104
  end.should raise_error( ArgumentError, 'Unknown Auto Rename Field Value: missing' )
105
105
  end
106
106
 
107
107
  end
108
108
 
109
- context 'using option :auto_rename_to_token' do
109
+ context 'using option :auto_tokenize' do
110
110
 
111
- it 'accepts :auto_rename_to_token when true' do
112
- subject.auto_rename_field( get_field , :auto_rename_to_token => true ).should == put_token
111
+ it 'accepts :auto_tokenize when true' do
112
+ subject.rename_field( get_field, :auto_tokenize => true ).should == put_token
113
113
  end
114
114
 
115
- it 'accepts :auto_rename_to_token when false' do
116
- subject.auto_rename_field( get_field, :auto_rename_to_token => false ).should == put_clean
115
+ it 'accepts :auto_tokenize when false' do
116
+ subject.rename_field( get_field, :auto_tokenize => false ).should == put_clean
117
117
  end
118
118
 
119
119
  it 'fails when not set' do
120
120
  lambda do
121
- subject.auto_rename_field('missing')
121
+ subject.rename_field('missing')
122
122
  end.should raise_error( ArgumentError, 'Unknown Auto Rename Field Value: missing' )
123
123
  end
124
124
  end
@@ -7,19 +7,19 @@ describe Boolean do
7
7
  EXTRA_KEY = 'ZAP'
8
8
  EXTRA_TEXT = 'ZIP ZAP ZOOM'
9
9
 
10
- it { should respond_to :boolean_fields }
11
- it { should respond_to :boolean_fields= }
12
-
10
+ it { should respond_to :boolean_lookup }
11
+ it { should respond_to :boolean_lookup= }
12
+
13
13
  describe '#initialize' do
14
14
 
15
- context 'using option :boolean_fields' do
15
+ context 'using option :boolean_lookup' do
16
16
  it 'accepts when given' do
17
- @subj = Boolean.new( :boolean_fields => FIELDS_EXP )
18
- @subj.boolean_fields.should == FIELDS_EXP
17
+ @subj = Boolean.new( :boolean_lookup => FIELDS_EXP )
18
+ @subj.boolean_lookup.should == FIELDS_EXP
19
19
  end
20
20
  it 'defaults as empty' do
21
21
  @subj = Boolean.new
22
- @subj.boolean_fields.should be_empty
22
+ @subj.boolean_lookup.should be_empty
23
23
  end
24
24
  end
25
25
 
@@ -86,7 +86,7 @@ describe Boolean do
86
86
 
87
87
  describe '#parse_field' do
88
88
 
89
- subject { Boolean.new :boolean_fields => FIELDS_EXP }
89
+ subject { Boolean.new :boolean_lookup => FIELDS_EXP }
90
90
 
91
91
  context 'with present field' do
92
92
 
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.11.30.1
4
+ version: 2011.12.04.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-30 00:00:00.000000000Z
12
+ date: 2011-12-04 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ghaki-bool
16
- requirement: &73929750 !ruby/object:Gem::Requirement
16
+ requirement: &82877040 !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: *73929750
24
+ version_requirements: *82877040
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &73929530 !ruby/object:Gem::Requirement
27
+ requirement: &82876800 !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: *73929530
35
+ version_requirements: *82876800
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rdoc
38
- requirement: &73929290 !ruby/object:Gem::Requirement
38
+ requirement: &82876570 !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: *73929290
46
+ version_requirements: *82876570
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: mocha
49
- requirement: &73929030 !ruby/object:Gem::Requirement
49
+ requirement: &82876330 !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: *73929030
57
+ version_requirements: *82876330
58
58
  description: Collection of helpers for regular expression helpers.
59
59
  email: gerald@kalafut.org
60
60
  executables: []