Class: FFIGen::Name

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#partsObject (readonly)

Returns the value of attribute parts.



196
197
198
# File 'lib/ffi_gen.rb', line 196

def parts
  @parts
end

#rawObject (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

Returns:

  • (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_classnameObject



111
112
113
# File 'lib/ffi_gen/java_output.rb', line 111

def to_java_classname
  format :camelcase, JAVA_KEYWORDS
end

#to_java_constantObject



115
116
117
# File 'lib/ffi_gen/java_output.rb', line 115

def to_java_constant
  format :upcase, :underscores, JAVA_KEYWORDS
end

#to_java_downcaseObject



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_classnameObject



99
100
101
# File 'lib/ffi_gen/ruby_output.rb', line 99

def to_ruby_classname
  format :camelcase, RUBY_KEYWORDS
end

#to_ruby_constantObject



103
104
105
# File 'lib/ffi_gen/ruby_output.rb', line 103

def to_ruby_constant
  format :upcase, :underscores, RUBY_KEYWORDS
end

#to_ruby_downcaseObject



95
96
97
# File 'lib/ffi_gen/ruby_output.rb', line 95

def to_ruby_downcase
  format :downcase, :underscores, RUBY_KEYWORDS
end