Module: XSD::CodeGen::GenSupport
- Included in:
- SOAP::Generator, WSDL::SOAP::ClassDefCreatorSupport, WSDL::SOAP::ClassNameCreator, WSDL::SOAP::ServantSkeltonCreator, ClassDef, CommentDef, MethodDef, ModuleDef
- Defined in:
- lib/xsd/codegen/gensupport.rb
Class Method Summary collapse
- .capitalize(target) ⇒ Object
- .constant?(word) ⇒ Boolean
- .keyword?(word) ⇒ Boolean
- .safeconstname(name) ⇒ Object
- .safeconstname?(name) ⇒ Boolean
- .safemethodname(name) ⇒ Object
- .safemethodname?(name) ⇒ Boolean
- .safevarname(name) ⇒ Object
- .safevarname?(name) ⇒ Boolean
- .uncapitalize(target) ⇒ Object
Instance Method Summary collapse
Class Method Details
.capitalize(target) ⇒ Object
156 157 158 |
# File 'lib/xsd/codegen/gensupport.rb', line 156 def capitalize(target) target.sub(/^([a-z])/) { $1.upcase } end |
.constant?(word) ⇒ Boolean
221 222 223 |
# File 'lib/xsd/codegen/gensupport.rb', line 221 def constant?(word) CONSTANTS.key?(word) end |
.keyword?(word) ⇒ Boolean
216 217 218 |
# File 'lib/xsd/codegen/gensupport.rb', line 216 def keyword?(word) KEYWORDS.key?(word) end |
.safeconstname(name) ⇒ Object
166 167 168 169 170 171 172 173 174 175 |
# File 'lib/xsd/codegen/gensupport.rb', line 166 def safeconstname(name) safename = name.scan(/[a-zA-Z0-9_]+/).collect { |ele| GenSupport.capitalize(ele) }.join if /\A[A-Z]/ !~ safename or keyword?(safename) or constant?(safename) "C_#{safename}" else safename end end |
.safeconstname?(name) ⇒ Boolean
178 179 180 |
# File 'lib/xsd/codegen/gensupport.rb', line 178 def safeconstname?(name) /\A[A-Z][a-zA-Z0-9_]*\z/ =~ name and !keyword?(name) end |
.safemethodname(name) ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/xsd/codegen/gensupport.rb', line 183 def safemethodname(name) postfix = name[/[=?!]$/] safename = name.scan(/[a-zA-Z0-9_]+/).join('_') safename = uncapitalize(safename) safename += postfix if postfix if /\A[a-z]/ !~ safename or keyword?(safename) "m_#{safename}" else safename end end |
.safemethodname?(name) ⇒ Boolean
196 197 198 |
# File 'lib/xsd/codegen/gensupport.rb', line 196 def safemethodname?(name) /\A[a-zA-Z_][a-zA-Z0-9_]*[=!?]?\z/ =~ name and !keyword?(name) end |
.safevarname(name) ⇒ Object
201 202 203 204 205 206 207 208 |
# File 'lib/xsd/codegen/gensupport.rb', line 201 def safevarname(name) safename = uncapitalize(name.scan(/[a-zA-Z0-9_]+/).join('_')) if /\A[a-z]/ !~ safename or keyword?(safename) "v_#{safename}" else safename end end |
.safevarname?(name) ⇒ Boolean
211 212 213 |
# File 'lib/xsd/codegen/gensupport.rb', line 211 def safevarname?(name) /\A[a-z_][a-zA-Z0-9_]*\z/ =~ name and !keyword?(name) end |
.uncapitalize(target) ⇒ Object
161 162 163 |
# File 'lib/xsd/codegen/gensupport.rb', line 161 def uncapitalize(target) target.sub(/^([A-Z])/) { $1.downcase } end |
Instance Method Details
#format(str, indent = nil) ⇒ Object
226 227 228 229 230 231 232 233 234 |
# File 'lib/xsd/codegen/gensupport.rb', line 226 def format(str, indent = nil) str = trim_eol(str) str = trim_indent(str) if indent str.gsub(/^/, " " * indent) else str end end |