mirror of
https://github.com/zhigang1992/rmq.git
synced 2026-01-12 17:52:17 +08:00
Merge pull request #229 from infinitered/symbolize_util
Symbolize utility method
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user