Class: MdlSql::Join

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Join

Returns a new instance of Join.



28
29
30
31
32
33
34
35
36
37
# File 'lib/mdlsql/join.rb', line 28

def initialize opts={}
	@cond1 = opts[:cond1]
	@cond2 = opts[:cond2]
	@table = Table.new opts[:table]
	@type = opts[:type]

	opts[:op].to_sym if opts[:op].is_a? String
	@op = opts[:op]
	@op ||= '='.to_sym
end

Instance Attribute Details

#col1Object (readonly)



26
# File 'lib/mdlsql/join.rb', line 26

attr_accessor :type, :table, :cond1, :cond2, :op

#col2Object (readonly)



26
# File 'lib/mdlsql/join.rb', line 26

attr_accessor :type, :table, :cond1, :cond2, :op

#cond1Object

Returns the value of attribute cond1.



26
27
28
# File 'lib/mdlsql/join.rb', line 26

def cond1
  @cond1
end

#cond2Object

Returns the value of attribute cond2.



26
27
28
# File 'lib/mdlsql/join.rb', line 26

def cond2
  @cond2
end

#opObject

Returns the value of attribute op.



26
27
28
# File 'lib/mdlsql/join.rb', line 26

def op
  @op
end

#tableObject

Returns the value of attribute table.



26
27
28
# File 'lib/mdlsql/join.rb', line 26

def table
  @table
end

#typeObject

Returns the value of attribute type.



26
27
28
# File 'lib/mdlsql/join.rb', line 26

def type
  @type
end

Instance Method Details

#to_mysqlObject

Literals must be made explicit with apostrophes.



40
41
42
43
44
45
46
47
48
# File 'lib/mdlsql/join.rb', line 40

def to_mysql
	# query = String.new
	query = "\n"
	query << @type.to_s.upcase << ' ' if @type
	query << 'JOIN'
	query << " " << @table.to_mysql
	query << "\nON #{@cond1} #{@op} #{@cond2}"
	return query
end