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
- #empty? ⇒ Boolean
- #format(*modes, keyword_blacklist) ⇒ Object
-
#initialize(generator, raw) ⇒ 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(generator, raw) ⇒ Name
Returns a new instance of Name.
198 199 200 201 202 |
# File 'lib/ffi_gen.rb', line 198 def initialize(generator, raw) @generator = generator @raw = raw @parts = @raw.is_a?(Array) ? raw : @raw.sub(/^(#{generator.prefixes.join('|')})/, '').split(/_|(?=[A-Z][a-z])|(?<=[a-z])(?=[A-Z])/).reject(&:empty?) end |
Instance Attribute Details
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
196 197 198 |
# File 'lib/ffi_gen.rb', line 196 def parts @parts end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
196 197 198 |
# File 'lib/ffi_gen.rb', line 196 def raw @raw end |
Instance Method Details
#empty? ⇒ Boolean
216 217 218 |
# File 'lib/ffi_gen.rb', line 216 def empty? @parts.empty? end |
#format(*modes, keyword_blacklist) ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/ffi_gen.rb', line 204 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
111 112 113 |
# File 'lib/ffi_gen/java_output.rb', line 111 def to_java_classname format :camelcase, JAVA_KEYWORDS end |
#to_java_constant ⇒ Object
115 116 117 |
# File 'lib/ffi_gen/java_output.rb', line 115 def to_java_constant format :upcase, :underscores, JAVA_KEYWORDS end |
#to_java_downcase ⇒ Object
107 108 109 |
# File 'lib/ffi_gen/java_output.rb', line 107 def to_java_downcase format :camelcase, :initial_downcase, JAVA_KEYWORDS end |
#to_ruby_classname ⇒ Object
99 100 101 |
# File 'lib/ffi_gen/ruby_output.rb', line 99 def to_ruby_classname format :camelcase, RUBY_KEYWORDS end |
#to_ruby_constant ⇒ Object
103 104 105 |
# File 'lib/ffi_gen/ruby_output.rb', line 103 def to_ruby_constant format :upcase, :underscores, RUBY_KEYWORDS end |
#to_ruby_downcase ⇒ Object
95 96 97 |
# File 'lib/ffi_gen/ruby_output.rb', line 95 def to_ruby_downcase format :downcase, :underscores, RUBY_KEYWORDS end |