awesome-cheeba 1.0.2 → 1.0.3

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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{cheeba}
5
- s.version = "1.0.2"
5
+ s.version = "1.0.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["So Awesome Man"]
@@ -6,6 +6,9 @@ module Cheeba
6
6
  SYMBOLIZE = false
7
7
  SYMBOLIZE_KEYS = false
8
8
  SYMBOLIZE_VALS = false
9
+ SYM_STR = false
10
+ SYM_STR_KEYS = false
11
+ SYM_STR_VALS = false
9
12
  AUTO_SYM = true
10
13
  AUTO_SYM_KEYS = false
11
14
  AUTO_SYM_VALS = false
@@ -37,6 +40,9 @@ module Cheeba
37
40
  "strip" => "strip keys & vals: \" both \" => \"both\"",
38
41
  "strip_keys" => "strip keys: \" key \" => \"key\"",
39
42
  "strip_vals" => "strip vals: \" val \" => \"val\"",
43
+ "sym_str" => "conv str (no int) k & v: \"b\" => :b",
44
+ "sym_str_keys" => "conv string keys(no int): \"key\" => :key",
45
+ "sym_str_vals" => "conv string vals(no int): \"val\" => :val",
40
46
  "symbolize" => "force conv keys & vals: \"both\" => :both",
41
47
  "symbolize_keys" => "force conv keys: \"key\" => :key",
42
48
  "symbolize_vals" => "force conv vals: \"val\" => :val",
@@ -50,6 +56,9 @@ module Cheeba
50
56
  :symbolize => SYMBOLIZE,
51
57
  :symbolize_keys => SYMBOLIZE_KEYS,
52
58
  :symbolize_vals => SYMBOLIZE_VALS,
59
+ :sym_str => SYM_STR,
60
+ :sym_str_keys => SYM_STR_KEYS,
61
+ :sym_str_vals => SYM_STR_VALS,
53
62
  :auto_sym => AUTO_SYM,
54
63
  :auto_sym_keys => AUTO_SYM_KEYS,
55
64
  :auto_sym_vals => AUTO_SYM_VALS,
@@ -1,7 +1,7 @@
1
1
  module Cheeba
2
2
  module Reader
3
3
  module Format
4
- ##
4
+ #
5
5
  # format datatypes in the parsed hash
6
6
  #
7
7
  def self.format(phs)
@@ -16,7 +16,7 @@ module Cheeba
16
16
  phs
17
17
  end
18
18
 
19
- ##
19
+ #
20
20
  # strips keys and values
21
21
  #
22
22
  def self.stripper(phs)
@@ -27,7 +27,7 @@ module Cheeba
27
27
  phs[:val] = phs[:val].to_s.strip if psp or psv
28
28
  end
29
29
 
30
- ##
30
+ #
31
31
  # adjusts options
32
32
  #
33
33
  def self.adjust_options(phs)
@@ -37,7 +37,7 @@ module Cheeba
37
37
  end
38
38
  end
39
39
 
40
- ##
40
+ #
41
41
  # true key
42
42
  #
43
43
  def self.key_to_true(phs)
@@ -52,7 +52,7 @@ module Cheeba
52
52
  end
53
53
  end
54
54
 
55
- ##
55
+ #
56
56
  # true val
57
57
  #
58
58
  def self.val_to_true(phs)
@@ -67,31 +67,35 @@ module Cheeba
67
67
  end
68
68
  end
69
69
 
70
- ##
70
+ #
71
71
  # symbolize key
72
72
  #
73
73
  def self.key_to_sym(phs)
74
- x = []
75
74
  is_str = (phs[:key] =~ /^\d*$/).nil?
75
+ x = []
76
+ x << (phs[:opt][:sym_str] && is_str).is_a?(TrueClass)
77
+ x << (phs[:opt][:sym_str_keys] && is_str).is_a?(TrueClass)
76
78
  x << phs[:opt][:symbolize].is_a?(TrueClass)
77
79
  x << (phs[:ask] && phs[:opt][:auto_sym_keys] && is_str).is_a?(TrueClass)
78
80
  x << phs[:opt][:symbolize_keys].is_a?(TrueClass)
79
- phs[:key] = phs[:key].to_sym if x.any?
81
+ phs[:key] = phs[:key].to_s.to_sym if x.any?
80
82
  end
81
83
 
82
- ##
84
+ #
83
85
  # symbolize val
84
86
  #
85
87
  def self.val_to_sym(phs)
86
- x = []
87
88
  is_str = (phs[:val] =~ /^\d*$/).nil?
89
+ x = []
90
+ x << (phs[:opt][:sym_str] && is_str).is_a?(TrueClass)
91
+ x << (phs[:opt][:sym_str_vals] && is_str).is_a?(TrueClass)
88
92
  x << phs[:opt][:symbolize].is_a?(TrueClass)
89
93
  x << (phs[:asv] && phs[:opt][:auto_sym_vals] && is_str).is_a?(TrueClass)
90
94
  x << phs[:opt][:symbolize_vals].is_a?(TrueClass)
91
- phs[:val] = phs[:val].to_sym if x.any? && !phs[:val].to_s.strip.empty?
95
+ phs[:val] = phs[:val].to_s.to_sym if (x.any? && !phs[:val].to_s.strip.empty?)
92
96
  end
93
97
 
94
- ##
98
+ #
95
99
  # key is parsed as string, so try to_i
96
100
  #
97
101
  def self.key_to_int(phs)
@@ -101,7 +105,7 @@ module Cheeba
101
105
  phs[:key] = self.string_to_int(phs[:key]) if x.any?
102
106
  end
103
107
 
104
- ##
108
+ #
105
109
  # val is parsed as string, so try to_i
106
110
  #
107
111
  def self.val_to_int(phs)
@@ -111,7 +115,7 @@ module Cheeba
111
115
  phs[:val] = self.string_to_int(phs[:val]) if x.any?
112
116
  end
113
117
 
114
- ##
118
+ #
115
119
  # returns int if string is convertable
116
120
  #
117
121
  def self.string_to_int(string)
@@ -1,3 +1,3 @@
1
1
  module Cheeba
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
3
3
  end
@@ -41,6 +41,92 @@ class TestReaderFormat < MiniTest::Unit::TestCase
41
41
  assert !phs2[:opt][:auto_sym_vals]
42
42
  end
43
43
 
44
+ def test_format_symbolize_keys_number_in_string
45
+ opt1 = @opt.merge({:symbolize_keys => true})
46
+ opt2 = @opt.merge({:int => true, :symbolize_keys => true})
47
+ phs1 = @phs.merge({:key => "1", :val => "1", :opt => opt1})
48
+ phs2 = @phs.merge({:key => "1", :val => "1", :opt => opt2})
49
+ act1 = @format.format(phs1)
50
+ act2 = @format.format(phs2)
51
+ exp1 = "1".to_sym
52
+ exp2 = "1".to_sym
53
+ assert_equal exp1, act1[:key]
54
+ assert_equal exp2, act2[:key]
55
+ end
56
+
57
+ def test_format_sym_str
58
+ opt1 = @opt.merge({:sym_str => true})
59
+ opt2 = @opt.merge({:int => true, :sym_str => true})
60
+ opt3 = opt1
61
+ phs1 = @phs.merge({:key => "1", :val => "1", :opt => opt1})
62
+ phs2 = @phs.merge({:key => "1", :val => "1", :opt => opt2})
63
+ phs3 = @phs.merge({:key => "awesome", :val => "awesome", :opt => opt3})
64
+ act1 = @format.format(phs1)
65
+ act2 = @format.format(phs2)
66
+ act3 = @format.format(phs3)
67
+ exp1 = "1"
68
+ exp2 = 1
69
+ exp3 = "awesome".to_sym
70
+ exp4 = "1"
71
+ exp5 = 1
72
+ exp6 = "awesome".to_sym
73
+ assert_equal exp1, act1[:key]
74
+ assert_equal exp2, act2[:key]
75
+ assert_equal exp3, act3[:key]
76
+ assert_equal exp4, act1[:val]
77
+ assert_equal exp5, act2[:val]
78
+ assert_equal exp6, act3[:val]
79
+ end
80
+
81
+ def test_format_sym_str_keys
82
+ opt1 = @opt.merge({:sym_str_keys => true})
83
+ opt2 = @opt.merge({:int => true, :sym_str_keys => true})
84
+ opt3 = opt1
85
+ phs1 = @phs.merge({:key => "1", :val => "1", :opt => opt1})
86
+ phs2 = @phs.merge({:key => "1", :val => "1", :opt => opt2})
87
+ phs3 = @phs.merge({:key => "awesome", :val => "awesome", :opt => opt3})
88
+ act1 = @format.format(phs1)
89
+ act2 = @format.format(phs2)
90
+ act3 = @format.format(phs3)
91
+ exp1 = "1"
92
+ exp2 = 1
93
+ exp3 = "awesome".to_sym
94
+ exp4 = "1"
95
+ exp5 = 1
96
+ exp6 = "awesome"
97
+ assert_equal exp1, act1[:key]
98
+ assert_equal exp2, act2[:key]
99
+ assert_equal exp3, act3[:key]
100
+ assert_equal exp4, act1[:val]
101
+ assert_equal exp5, act2[:val]
102
+ assert_equal exp6, act3[:val]
103
+ end
104
+
105
+ def test_format_sym_str_vals
106
+ opt1 = @opt.merge({:sym_str_vals => true})
107
+ opt2 = @opt.merge({:int => true, :sym_str_vals => true})
108
+ opt3 = opt1
109
+ opt1 = @opt.merge({:sym_str_vals => true})
110
+ phs1 = @phs.merge({:key => "1", :val => "1", :opt => opt1})
111
+ phs2 = @phs.merge({:key => "1", :val => "1", :opt => opt2})
112
+ phs3 = @phs.merge({:key => "awesome", :val => "awesome", :opt => opt3})
113
+ act1 = @format.format(phs1)
114
+ act2 = @format.format(phs2)
115
+ act3 = @format.format(phs3)
116
+ exp1 = "1"
117
+ exp2 = 1
118
+ exp3 = "awesome"
119
+ exp4 = "1"
120
+ exp5 = 1
121
+ exp6 = "awesome".to_sym
122
+ assert_equal exp1, act1[:key]
123
+ assert_equal exp2, act2[:key]
124
+ assert_equal exp3, act3[:key]
125
+ assert_equal exp4, act1[:val]
126
+ assert_equal exp5, act2[:val]
127
+ assert_equal exp6, act3[:val]
128
+ end
129
+
44
130
  #
45
131
  # strip different things
46
132
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awesome-cheeba
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - So Awesome Man