Class: Cyby::Kintone::Query::Where

Inherits:
Object
  • Object
show all
Defined in:
lib/cyby/kintone/query/where.rb

Instance Method Summary collapse

Constructor Details

#initialize(cond = "", *params) ⇒ Where

Returns a new instance of Where.



5
6
7
8
# File 'lib/cyby/kintone/query/where.rb', line 5

def initialize(cond = "", *params)
  @cond = cond
  @params = params
end

Instance Method Details

#param_to_s(param) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cyby/kintone/query/where.rb', line 28

def param_to_s(param)
  case param
  when String, Date, DateTime
    '"' + param.to_s + '"'
  when Time
    '"' + param.strftime("%Y-%m-%dT%H:%M%:z") + '"'
  when Array
    '("' + param.join('","') + '")'
  else
    param.to_s
  end
end

#to_queryObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cyby/kintone/query/where.rb', line 10

def to_query
  if @params.empty?
    @cond
  else
    conds = @cond.split("?")
    unless conds.count == @params.count
      fail "Condition params count mismatch!"
    end
    i = 0
    cond = ""
    while i < conds.count
      cond += conds[i] + param_to_s(@params[i])
      i += 1
    end
    cond
  end
end