class Alphavantage::NormalizeKey

Public Class Methods

new(key:) click to toggle source
# File lib/alphavantage/normalize_key.rb, line 3
def initialize(key:)
  @key = key
end

Public Instance Methods

call() click to toggle source
# File lib/alphavantage/normalize_key.rb, line 7
def call
  return @key if is_date?(@key)
  underscore_key(sanitize_key(@key))
end

Private Instance Methods

is_date?(key) click to toggle source
# File lib/alphavantage/normalize_key.rb, line 26
def is_date?(key)
  !/(\d{4}-\d{2}-\d{2})/.match(key.to_s).nil?
end
sanitize_key(key) click to toggle source
# File lib/alphavantage/normalize_key.rb, line 22
def sanitize_key(key)
  key.tr('.():/','').gsub(/^\d+.?\s/, "").tr(' ','_')
end
underscore_key(key) click to toggle source
# File lib/alphavantage/normalize_key.rb, line 14
def underscore_key(key)
  key.to_s.gsub(/::/, '/').
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
  gsub(/([a-z\d])([A-Z])/,'\1_\2').
  tr("-", "_").
  downcase.to_sym
end