Module: Rubeetup::Utilities

Included in:
MeetupCatalog, Request, RequestResponse, RequestSender, Requester
Defined in:
lib/rubeetup/utilities.rb

Overview

Provides some miscellaneous methods for mix-ins

Instance Method Summary collapse

Instance Method Details

#blank?(obj) ⇒ Boolean

Returns whether the object is blank as per Ruby Active Support.

Parameters:

  • obj (Object)

    an object

Returns:

  • (Boolean)

    whether the object is blank as per Ruby Active Support



18
19
20
# File 'lib/rubeetup/utilities.rb', line 18

def blank?(obj)
  obj.nil? || obj == false || obj.empty? || obj =~ /^\s+$/
end

#collection_symbolyzer(array) ⇒ Array<Symbol, Array...>

Note:

For speed and simplicity no error checking is performed

Transforms the strings into a possibly nested collection, into symbols

Parameters:

  • array (Array<String, Array...>)

    a possibly recursive collection of strings

Returns:

  • (Array<Symbol, Array...>)

    a possibly recursive collection of Symbols



38
39
40
# File 'lib/rubeetup/utilities.rb', line 38

def collection_symbolyzer(array)
  array.map {|elem| elem.is_a?(String) ? elem.to_sym : collection_symbolyzer(elem)}
end

#present?(obj) ⇒ Boolean

Determines if the object is not blank (see #blank?)

Returns:

  • (Boolean)


10
11
12
# File 'lib/rubeetup/utilities.rb', line 10

def present?(obj)
  !blank?(obj)
end

#stringify(options) ⇒ String

Generates a string of key values to include in URL’s

Parameters:

  • options (Hash{Symbol=>String})

    holds options for a request

Returns:

  • (String)

    a sringified representation of a Hash of options



27
28
29
30
# File 'lib/rubeetup/utilities.rb', line 27

def stringify(options)
  return '' unless options.respond_to? :map
  options.map { |key, val| "#{key}=#{val}" if key && val }.compact.join('&')
end