Module: XSD::CodeGen::GenSupport
- Included in:
- ClassDef, CommentDef, MethodDef, ModuleDef
- Defined in:
- lib/xsd/codegen/gensupport.rb
Instance Method Summary collapse
- #capitalize(target) ⇒ Object
- #format(str, indent = nil) ⇒ Object
- #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 Details
#capitalize(target) ⇒ Object
58 59 60 |
# File 'lib/xsd/codegen/gensupport.rb', line 58 def capitalize(target) target.sub(/^([a-z])/) { $1.tr!('[a-z]', '[A-Z]') } end |
#format(str, indent = nil) ⇒ Object
119 120 121 122 123 124 125 126 127 |
# File 'lib/xsd/codegen/gensupport.rb', line 119 def format(str, indent = nil) str = trim_eol(str) str = trim_indent(str) if indent str.gsub(/^/, " " * indent) else str end end |
#keyword?(word) ⇒ Boolean
114 115 116 |
# File 'lib/xsd/codegen/gensupport.rb', line 114 def keyword?(word) KEYWORD.key?(word) end |
#safeconstname(name) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/xsd/codegen/gensupport.rb', line 68 def safeconstname(name) safename = name.scan(/[a-zA-Z0-9_]+/).collect { |ele| GenSupport.capitalize(ele) }.join if /^[A-Z]/ !~ safename or keyword?(safename) safename = "C_#{safename}" end safename end |
#safeconstname?(name) ⇒ Boolean
79 80 81 |
# File 'lib/xsd/codegen/gensupport.rb', line 79 def safeconstname?(name) /\A[A-Z][a-zA-Z0-9_]*\z/ =~ name and !keyword?(name) end |
#safemethodname(name) ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/xsd/codegen/gensupport.rb', line 84 def safemethodname(name) safename = name.scan(/[a-zA-Z0-9_]+/).join('_') safename = uncapitalize(safename) if /^[a-z]/ !~ safename safename = "m_#{safename}" end safename end |
#safemethodname?(name) ⇒ Boolean
94 95 96 |
# File 'lib/xsd/codegen/gensupport.rb', line 94 def safemethodname?(name) /\A[a-zA-Z_][a-zA-Z0-9_]*[=!?]?\z/ =~ name end |
#safevarname(name) ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/xsd/codegen/gensupport.rb', line 99 def safevarname(name) safename = uncapitalize(name.scan(/[a-zA-Z0-9_]+/).join('_')) if /^[a-z]/ !~ safename or keyword?(safename) "v_#{safename}" else safename end end |
#safevarname?(name) ⇒ Boolean
109 110 111 |
# File 'lib/xsd/codegen/gensupport.rb', line 109 def safevarname?(name) /\A[a-z_][a-zA-Z0-9_]*\z/ =~ name and !keyword?(name) end |
#uncapitalize(target) ⇒ Object
63 64 65 |
# File 'lib/xsd/codegen/gensupport.rb', line 63 def uncapitalize(target) target.sub(/^([A-Z])/) { $1.tr!('[A-Z]', '[a-z]') } end |