Module: XSD::CodeGen::GenSupport

Included in:
WSDL::SOAP::ClassDefCreatorSupport, WSDL::SOAP::ServantSkeltonCreator, ClassDef, CommentDef, MethodDef, ModuleDef
Defined in:
lib/action_web_service/xsd/codegen/gensupport.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.capitalize(target) ⇒ Object



58
59
60
# File 'lib/action_web_service/xsd/codegen/gensupport.rb', line 58

def capitalize(target)
  target.sub(/^([a-z])/) { $1.tr!('[a-z]', '[A-Z]') }
end

.keyword?(word) ⇒ Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/action_web_service/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/action_web_service/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

Returns:

  • (Boolean)


79
80
81
# File 'lib/action_web_service/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/action_web_service/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

Returns:

  • (Boolean)


94
95
96
# File 'lib/action_web_service/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/action_web_service/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

Returns:

  • (Boolean)


109
110
111
# File 'lib/action_web_service/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/action_web_service/xsd/codegen/gensupport.rb', line 63

def uncapitalize(target)
  target.sub(/^([A-Z])/) { $1.tr!('[A-Z]', '[a-z]') }
end

Instance Method Details

#format(str, indent = nil) ⇒ Object



119
120
121
122
123
124
125
126
127
# File 'lib/action_web_service/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