Class: MdlSql::Join
- Inherits:
-
Object
- Object
- MdlSql::Join
- Defined in:
- lib/mdlsql/join.rb
Instance Attribute Summary collapse
- #col1 ⇒ Object readonly
- #col2 ⇒ Object readonly
-
#cond1 ⇒ Object
Returns the value of attribute cond1.
-
#cond2 ⇒ Object
Returns the value of attribute cond2.
-
#op ⇒ Object
Returns the value of attribute op.
-
#table ⇒ Object
Returns the value of attribute table.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Join
constructor
A new instance of Join.
-
#to_mysql ⇒ Object
Literals must be made explicit with apostrophes.
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
#col1 ⇒ Object (readonly)
26 |
# File 'lib/mdlsql/join.rb', line 26 attr_accessor :type, :table, :cond1, :cond2, :op |
#col2 ⇒ Object (readonly)
26 |
# File 'lib/mdlsql/join.rb', line 26 attr_accessor :type, :table, :cond1, :cond2, :op |
#cond1 ⇒ Object
Returns the value of attribute cond1.
26 27 28 |
# File 'lib/mdlsql/join.rb', line 26 def cond1 @cond1 end |
#cond2 ⇒ Object
Returns the value of attribute cond2.
26 27 28 |
# File 'lib/mdlsql/join.rb', line 26 def cond2 @cond2 end |
#op ⇒ Object
Returns the value of attribute op.
26 27 28 |
# File 'lib/mdlsql/join.rb', line 26 def op @op end |
#table ⇒ Object
Returns the value of attribute table.
26 27 28 |
# File 'lib/mdlsql/join.rb', line 26 def table @table end |
#type ⇒ Object
Returns the value of attribute type.
26 27 28 |
# File 'lib/mdlsql/join.rb', line 26 def type @type end |
Instance Method Details
#to_mysql ⇒ Object
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 |