Module: TingYun::Helper
Overview
A singleton for shared generic helper methods
Instance Method Summary collapse
-
#correctly_encoded(string) ⇒ Object
noop.
- #instance_method_visibility(klass, method_name) ⇒ Object
- #instance_methods_include?(klass, method_name) ⇒ Boolean
- #milliseconds_to_seconds(milliseconds) ⇒ Object
- #time_to_f_millis(time) ⇒ Object
- #time_to_millis(time) ⇒ Object
Instance Method Details
#correctly_encoded(string) ⇒ Object
noop
22 23 24 25 26 27 |
# File 'lib/ting_yun/support/helper.rb', line 22 def correctly_encoded(string) return string unless string.is_a? String # The .dup here is intentional, since force_encoding mutates the target, # and we don't know who is going to use this string downstream of us. string.valid_encoding? ? string : string.dup.force_encoding("ASCII-8BIT") end |
#instance_method_visibility(klass, method_name) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/ting_yun/support/helper.rb', line 27 def instance_method_visibility(klass, method_name) if klass.private_instance_methods.map{|s|s.to_sym}.include? method_name.to_sym :private elsif klass.protected_instance_methods.map{|s|s.to_sym}.include? method_name.to_sym :protected else :public end end |
#instance_methods_include?(klass, method_name) ⇒ Boolean
37 38 39 40 41 42 43 44 |
# File 'lib/ting_yun/support/helper.rb', line 37 def instance_methods_include?(klass, method_name) method_name_sym = method_name.to_sym ( klass.instance_methods.map{ |s| s.to_sym }.include?(method_name_sym) || klass.protected_instance_methods.map{ |s|s.to_sym }.include?(method_name_sym) || klass.private_instance_methods.map{ |s|s.to_sym }.include?(method_name_sym) ) end |
#milliseconds_to_seconds(milliseconds) ⇒ Object
54 55 56 |
# File 'lib/ting_yun/support/helper.rb', line 54 def milliseconds_to_seconds(milliseconds) milliseconds / 1000.0 end |
#time_to_f_millis(time) ⇒ Object
50 51 52 |
# File 'lib/ting_yun/support/helper.rb', line 50 def time_to_f_millis(time) (time.to_f * 1000) end |
#time_to_millis(time) ⇒ Object
46 47 48 |
# File 'lib/ting_yun/support/helper.rb', line 46 def time_to_millis(time) (time.to_f * 1000).round end |