Class: MdlSql::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/mdlsql/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, as = nil) ⇒ Table

Returns a new instance of Table.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/mdlsql/table.rb', line 21

def initialize name, as=nil

	if name.is_a? String
		name = name.to_sym
	elsif name.is_a? Hash
		name = name.flatten

		if name[1].is_a? String
			as = name[1].to_sym
		else
			as = name[1]
		end

		if name[0].is_a? String
			name = name[0].to_sym
		else
			name = name[0]
		end
	end

	as = as.to_sym if as.is_a? String

	@name = name
	@as = as if as
end

Instance Attribute Details

#asObject

Returns the value of attribute as.



20
21
22
# File 'lib/mdlsql/table.rb', line 20

def as
  @as
end

#nameObject

Returns the value of attribute name.



20
21
22
# File 'lib/mdlsql/table.rb', line 20

def name
  @name
end

Instance Method Details

#to_mysqlObject



47
48
49
50
51
52
# File 'lib/mdlsql/table.rb', line 47

def to_mysql
	s = String.new
	s << @name.to_s
	s << ' AS ' << @as.to_s if @as
	return s
end