Module: Xqsr3::StringUtilities::ToSymbol::ToSymbol_Helper_
- Defined in:
- lib/xqsr3/string_utilities/to_symbol.rb
Overview
:nodoc:
Defined Under Namespace
Modules: Constants
Class Method Summary collapse
Class Method Details
.string_to_symbol_with_options_(s, options) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/xqsr3/string_utilities/to_symbol.rb', line 70 def self. s, case s when ::String ; else if s.respond_to? :to_str s = s.to_str else raise TypeError, "string argument must be of type #{::String} or a type that will respond to to_str" end end case when ::Hash ; else raise TypeError, "options must be of type #{::Hash}, #{.class} given" end return nil if s.empty? transform_characters = [:transform_characters] || [] s.chars.map.with_index do |c, index| if 0 != index && Constants::SymbolCharactersN.include?(c) c elsif 0 == index && Constants::SymbolCharacters0.include?(c) c else case c when '-' return nil if [:reject_hyphens] when ' ' return nil if [:reject_spaces] || [:reject_whitespace] when ?\t return nil if [:reject_tabs] || [:reject_whitespace] else return nil unless transform_characters.include? c end '_' end end.join('').to_sym end |