module TwelvedataRuby::Utils

Public Class Methods

call_block_if_truthy(truthy_val, return_this=nil, &block) click to toggle source
# File lib/twelvedata_ruby/utils.rb, line 28
def self.call_block_if_truthy(truthy_val, return_this=nil, &block)
  truthy_val ? block.call : return_this
end
camelize(str) click to toggle source
# File lib/twelvedata_ruby/utils.rb, line 16
def self.camelize(str)
  str.to_s.split("_").map(&:capitalize).join
end
demodulize(obj) click to toggle source
# File lib/twelvedata_ruby/utils.rb, line 5
def self.demodulize(obj)
  obj.to_s.gsub(/^.+::/, "")
end
empty_to_nil(obj) click to toggle source
# File lib/twelvedata_ruby/utils.rb, line 20
def self.empty_to_nil(obj)
  !obj.nil? && obj.empty? ? nil : obj
end
return_nil_unless_true(is_true, &block) click to toggle source
# File lib/twelvedata_ruby/utils.rb, line 32
def self.return_nil_unless_true(is_true, &block)
  call_block_if_truthy(is_true == true) { block.call }
end
to_a(objects) click to toggle source
# File lib/twelvedata_ruby/utils.rb, line 24
def self.to_a(objects)
  objects.is_a?(Array) ? objects : [objects]
end
to_d(obj, default_value=nil) click to toggle source

Converts a string to integer an all integer or nothing

# File lib/twelvedata_ruby/utils.rb, line 10
def self.to_d(obj, default_value=nil)
  return obj if obj.is_a?(Integer)

  obj.to_s.match(/^\d+$/) {|m| Integer(m[0]) } || default_value
end