Module: ROBundle::Util

Defined in:
lib/ro-bundle/util.rb

Overview

A module with lots of utility functions.

Class Method Summary collapse

Class Method Details

.clean_json(structure) ⇒ Object

:call-seq:

clean_json(json_hash) -> Hash

Remove empty strings and nils from a json hash structure.



19
20
21
22
23
# File 'lib/ro-bundle/util.rb', line 19

def self.clean_json(structure)
  structure.dup.delete_if do |_, v|
    v.nil? || (v.respond_to?(:empty?) && v.empty?)
  end
end

.is_absolute_uri?(uri) ⇒ Boolean

:call-seq:

is_absolute_uri?(uri) -> true or false

Is the supplied URI absolute? An absolute URI is a valid URI that starts with a scheme, such as http, https or urn.

Returns:

  • (Boolean)


39
40
41
42
43
44
# File 'lib/ro-bundle/util.rb', line 39

def self.is_absolute_uri?(uri)
  uri = URI.parse(uri) unless uri.is_a?(URI)
  !uri.scheme.nil?
rescue URI::InvalidURIError
  false
end

.parse_time(time) ⇒ Object

:call-seq:

parse_time(time) -> Time

Parse a time string into a Time object. Does not try to parse nil.



29
30
31
32
# File 'lib/ro-bundle/util.rb', line 29

def self.parse_time(time)
  return if time.nil?
  Time.parse(time)
end

.strip_leading_slash(string) ⇒ Object

:call-seq:

strip_leading_slash(string)

Return the supplied string with a leading slash removed.



50
51
52
53
# File 'lib/ro-bundle/util.rb', line 50

def self.strip_leading_slash(string)
  return if string.nil?
  string.sub(/^\//, "")
end