Sha256: edc12457a3287bbe016e7820c770d3e2319f0bb7166c937ad48151bd37aaf2d8
Contents?: true
Size: 581 Bytes
Versions: 2
Compression:
Stored size: 581 Bytes
Contents
module Alphavantage class NormalizeKey def initialize(key:) @key = key end def call return @key if is_date?(@key) underscore_key(sanitize_key(@key)) end private 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 def sanitize_key(key) key.tr('.():/','').gsub(/^\d+.?\s/, "").tr(' ','_') end def is_date?(key) !/(\d{4}-\d{2}-\d{2})/.match(key.to_s).nil? end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
alphavantage-1.2.0 | lib/alphavantage/normalize_key.rb |
alphavantage-1.1.0 | lib/alphavantage/normalize_key.rb |