Class: SwiftGenerator::SwiftEnumCase

Inherits:
Object
  • Object
show all
Defined in:
lib/swift_generator/code_generation/swift_class_generation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(enum_def, case_name, raw_value = nil) ⇒ SwiftEnumCase

Returns a new instance of SwiftEnumCase.



255
256
257
258
259
260
261
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 255

def initialize( enum_def, case_name, raw_value=nil )
	@enum_def = enum_def
	@raw_value = raw_value
	@case_name = case_name

	enum_def.add_case( self )
end

Instance Attribute Details

#case_nameObject

Returns the value of attribute case_name.



253
254
255
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 253

def case_name
  @case_name
end

#enum_defObject

Returns the value of attribute enum_def.



251
252
253
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 251

def enum_def
  @enum_def
end

#raw_valueObject

Returns the value of attribute raw_value.



252
253
254
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 252

def raw_value
  @raw_value
end

Instance Method Details

#declaration_linesObject



263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/swift_generator/code_generation/swift_class_generation.rb', line 263

def declaration_lines()
	raw_value_literal = @raw_value
	case enum_def.enum_raw_type
		when "String"
			raw_value_literal = "\"#{@raw_value}\""
	end

	if raw_value.nil?
		["case #{@case_name}"]
	else
		["case #{@case_name} = #{raw_value_literal}"]
	end
end