From 4517fc5266b97f6fe4f23544522ab23ba9e30ad1 Mon Sep 17 00:00:00 2001 From: Gant Date: Sat, 21 Mar 2015 19:05:58 -0500 Subject: [PATCH 1/3] added symbolize util --- motion/ruby_motion_query/utils.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/motion/ruby_motion_query/utils.rb b/motion/ruby_motion_query/utils.rb index df837d9..e19a66d 100644 --- a/motion/ruby_motion_query/utils.rb +++ b/motion/ruby_motion_query/utils.rb @@ -18,6 +18,16 @@ module RubyMotionQuery end end + # Converts any string to a friendly symbol version. + # Example: RubyMotionQuery::RMQ.symbolize("This is a TEST!") + # #=> :this_is_a_test + # + # @param [String] + # @return [Symbol] + def symbolize(s) + s.to_s.gsub(/\s+/,"_").downcase.to_sym + end + # @param view # @return [UIViewController] The controller the view it is sitting in, or nil if it's not sitting anywhere in particular def controller_for_view(view) From 9fa9947bad524c449fa761932a26cfc7abf6eaa1 Mon Sep 17 00:00:00 2001 From: Gant Date: Sat, 21 Mar 2015 19:17:15 -0500 Subject: [PATCH 2/3] ignore punctuation too --- motion/ruby_motion_query/utils.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/motion/ruby_motion_query/utils.rb b/motion/ruby_motion_query/utils.rb index e19a66d..94f1e9b 100644 --- a/motion/ruby_motion_query/utils.rb +++ b/motion/ruby_motion_query/utils.rb @@ -19,13 +19,13 @@ module RubyMotionQuery end # Converts any string to a friendly symbol version. - # Example: RubyMotionQuery::RMQ.symbolize("This is a TEST!") + # Example: RubyMotionQuery::RMQ.symbolize("This is a TEST!!") # #=> :this_is_a_test # # @param [String] # @return [Symbol] def symbolize(s) - s.to_s.gsub(/\s+/,"_").downcase.to_sym + s.to_s.gsub(/\s+/,"_").gsub(/\W+/,"").downcase.to_sym end # @param view From 36c1f6d5a2f5e684a5fea29e1f541387d516b1b6 Mon Sep 17 00:00:00 2001 From: Gant Date: Sat, 21 Mar 2015 19:17:27 -0500 Subject: [PATCH 3/3] tests for symbolize --- spec/utils.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spec/utils.rb b/spec/utils.rb index ef46dd2..aff8932 100644 --- a/spec/utils.rb +++ b/spec/utils.rb @@ -19,7 +19,7 @@ describe 'utils' do end it 'should return false if module is passed to is_class?' do - @rmq.is_class?(TestIsClassModule).should == false + @rmq.is_class?(TestIsClassModule).should == false end it 'should return false if non class is passed to is_class?' do @@ -52,6 +52,12 @@ describe 'utils' do @rmq.is_blank?({not_emtpy: true}).should == false end + it 'should return a usable snake_cased symbol' do + @rmq.symbolize("Help").should == :help + @rmq.symbolize("This is a test").should == :this_is_a_test + @rmq.symbolize("This Works Great!!!").should == :this_works_great + end + it 'should return a string of a view' do v = UIView.alloc.initWithFrame(CGRectZero) s = @rmq.view_to_s(v)