Module: Baidu::Support::Util
- Defined in:
- lib/baidu/support/util.rb
Class Method Summary collapse
-
.blank?(obj) ⇒ Boolean
Check whether
obj
is blank or not. -
.clean_params(params) ⇒ Hash
Delete object which value is
nil
from params. -
.edit_path(path) ⇒ String
Change “\ ? | ” > < : “* to ”_“, multi ”/“ to one ”/“.
-
.encode_params(params) ⇒ String
Encode params to www form style.
Class Method Details
.blank?(obj) ⇒ Boolean
Check whether obj
is blank or not
17 18 19 20 21 22 23 24 25 |
# File 'lib/baidu/support/util.rb', line 17 def blank?(obj) case obj when String then /[^[:space:]]/ !~ obj when NilClass then true when TrueClass then false when FalseClass then true else obj.respond_to?(:empty?) ? obj.empty? : !obj end end |
.clean_params(params) ⇒ Hash
Delete object which value is nil
from params
44 45 46 47 48 49 |
# File 'lib/baidu/support/util.rb', line 44 def clean_params(params) raise ArgumentError, 'require Hash instance' unless params.is_a? Hash unless blank? params params.delete_if { |k, v| v.nil? } end end |
.edit_path(path) ⇒ String
Change “\ ? | ” > < : “* to ”_“, multi ”/“ to one ”/“
56 57 58 59 60 61 62 63 |
# File 'lib/baidu/support/util.rb', line 56 def edit_path(path) return nil if path.nil? path = path.gsub(/\/+/, '/') path = path.gsub(/\A[\s\.]*/, '') path = path.gsub(/[\s\.]*\z/, '') path = path.gsub(/[\\\|\?"><:\*]/, '_') path end |
.encode_params(params) ⇒ String
Encode params to www form style
33 34 35 36 |
# File 'lib/baidu/support/util.rb', line 33 def encode_params(params) raise ArgumentError, 'require Hash instance' unless params.is_a? Hash URI::encode_www_form params end |