Class: FFIGen::Name
- Inherits:
-
Object
- Object
- FFIGen::Name
- Defined in:
- lib/ffi_gen.rb,
lib/ffi_gen/java_output.rb,
lib/ffi_gen/ruby_output.rb
Constant Summary collapse
- JAVA_KEYWORDS =
%w{abstract assert boolean break byte case catch char class const continue default do double else enum extends final finally float for goto if implements import instanceof int interface long native new package private protected public return short static strictfp super switch synchronized this throw throws transient try void volatile while}
- RUBY_KEYWORDS =
%w{alias and begin break case class def defined do else elsif end ensure false for if in module next nil not or redo rescue retry return self super then true undef unless until when while yield BEGIN END}
Instance Attribute Summary collapse
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
- #format(*modes, keyword_blacklist) ⇒ Object
-
#initialize(parts, raw = nil) ⇒ Name
constructor
A new instance of Name.
- #to_java_classname ⇒ Object
- #to_java_constant ⇒ Object
- #to_java_downcase ⇒ Object
- #to_ruby_classname ⇒ Object
- #to_ruby_constant ⇒ Object
- #to_ruby_downcase ⇒ Object
Constructor Details
#initialize(parts, raw = nil) ⇒ Name
Returns a new instance of Name.
188 189 190 191 |
# File 'lib/ffi_gen.rb', line 188 def initialize(parts, raw = nil) @parts = parts @raw = raw end |
Instance Attribute Details
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
186 187 188 |
# File 'lib/ffi_gen.rb', line 186 def parts @parts end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
186 187 188 |
# File 'lib/ffi_gen.rb', line 186 def raw @raw end |
Instance Method Details
#format(*modes, keyword_blacklist) ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/ffi_gen.rb', line 193 def format(*modes, keyword_blacklist) parts = @parts.dup parts.map!(&:downcase) if modes.include? :downcase parts.map!(&:upcase) if modes.include? :upcase parts.map! { |s| s[0].upcase + s[1..-1] } if modes.include? :camelcase parts[0] = parts[0][0].downcase + parts[0][1..-1] if modes.include? :initial_downcase str = parts.join(modes.include?(:underscores) ? "_" : "") str.sub!(/^\d/, '_\0') # fix illegal beginnings str = "#{str}_" if keyword_blacklist.include? str str end |
#to_java_classname ⇒ Object
51 52 53 |
# File 'lib/ffi_gen/java_output.rb', line 51 def to_java_classname format :camelcase, JAVA_KEYWORDS end |
#to_java_constant ⇒ Object
55 56 57 |
# File 'lib/ffi_gen/java_output.rb', line 55 def to_java_constant format :upcase, :underscores, JAVA_KEYWORDS end |
#to_java_downcase ⇒ Object
47 48 49 |
# File 'lib/ffi_gen/java_output.rb', line 47 def to_java_downcase format :camelcase, :initial_downcase, JAVA_KEYWORDS end |
#to_ruby_classname ⇒ Object
25 26 27 |
# File 'lib/ffi_gen/ruby_output.rb', line 25 def to_ruby_classname format :camelcase, RUBY_KEYWORDS end |
#to_ruby_constant ⇒ Object
29 30 31 |
# File 'lib/ffi_gen/ruby_output.rb', line 29 def to_ruby_constant format :upcase, :underscores, RUBY_KEYWORDS end |
#to_ruby_downcase ⇒ Object
21 22 23 |
# File 'lib/ffi_gen/ruby_output.rb', line 21 def to_ruby_downcase format :downcase, :underscores, RUBY_KEYWORDS end |