Merge pull request #229 from infinitered/symbolize_util

Symbolize utility method
This commit is contained in:
Todd Werth
2015-03-26 13:35:00 -07:00
2 changed files with 17 additions and 1 deletions

View File

@@ -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+/,"_").gsub(/\W+/,"").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)

View File

@@ -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)