Sha256: 727f67dc695bd5b69a90780bceac2bc1b7db9986f82aa1e6328f3572e5d67649
Contents?: true
Size: 1.37 KB
Versions: 1
Compression:
Stored size: 1.37 KB
Contents
# frozen_string_literal: true require 'nori/core_ext' require 'rubykeyword' require 'humanize' # Override string object to provide convenience methods for Strings class String # @todo: Have method of replacing all # @return [String] Remove many complex characters to make a key for a Ruby Hash that is usable def to_key_name tr(' ,-', '_').tr("'/():$#", '').tr('&', '').gsub('<', 'gt').remove_macrons.snakecase.gsub('__', '_') .humanize_numbered_string end # Convert string starting with number to a human string def humanize_numbered_string self[0] = self[0].to_i.zero? ? self[0] : self[0].to_i.humanize self end # @return [String] Return string without macrons, used for filenames and ruby methods def remove_macrons tr('ā', 'a').tr('ē', 'e').tr('ō', 'o').tr('ī', 'i').tr('ū', 'u') end # A ruby friendly method name that is not taken by keywords like 'class', 'alias' # @return [String] Ruby friendly name that can be used as method name def unused_ruby_name name = to_key_name name.keyword? ? "my_#{name}" : name end # @return [String] Zulu time stamp for string def to_zulu_date_string Time.parse(self).strftime('%Y-%m-%dT%H:%M:%S.000Z') end # @return [Boolean] Whether string can be parsed into a time def type_of_time? Time.parse self rescue ArgumentError false else true end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
leap_salesforce-0.1.3 | lib/leap_salesforce/ext/string.rb |