Class: Getto::Repository::Sequel::Search::Where

Inherits:
Object
  • Object
show all
Defined in:
lib/getto/repository/sequel/search.rb

Instance Method Summary collapse

Constructor Details

#initialize(query:, where:) ⇒ Where



109
110
111
112
# File 'lib/getto/repository/sequel/search.rb', line 109

def initialize(query:, where:)
  @query = query
  @where = where
end

Instance Method Details

#cont(column) ⇒ Object



40
41
42
# File 'lib/getto/repository/sequel/search.rb', line 40

def cont(column)
  ->(value){ ::Sequel.like(column, "%#{value}%") }
end

#cont_as_hira(column) ⇒ Object



57
58
59
60
61
# File 'lib/getto/repository/sequel/search.rb', line 57

def cont_as_hira(column)
  ->(value){
    cont(column).call NKF.nkf("--hiragana -w", value)
  }
end

#cont_as_kana(column) ⇒ Object



51
52
53
54
55
# File 'lib/getto/repository/sequel/search.rb', line 51

def cont_as_kana(column)
  ->(value){
    cont(column).call NKF.nkf("--katakana -w", value)
  }
end

#cont_hira_or_kana(column) ⇒ Object



44
45
46
47
48
49
# File 'lib/getto/repository/sequel/search.rb', line 44

def cont_hira_or_kana(column)
  self.or([
    cont_as_kana(column),
    cont_as_hira(column),
  ])
end

#eq(column) ⇒ Object



63
64
65
# File 'lib/getto/repository/sequel/search.rb', line 63

def eq(column)
  ->(value){ { column => value } }
end

#gteq(column) ⇒ Object



67
68
69
# File 'lib/getto/repository/sequel/search.rb', line 67

def gteq(column)
  ->(value){ ::Sequel.lit("? >= ?", column, value) }
end

#in(&query) ⇒ Object



88
89
90
91
92
93
94
95
# File 'lib/getto/repository/sequel/search.rb', line 88

def in(&query)
  ->(value){
    where = value.map(&query).compact
    unless where.empty?
      ::Sequel.|(*where)
    end
  }
end

#is_not_null(column, map) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/getto/repository/sequel/search.rb', line 75

def is_not_null(column,map)
  ->(value){
    if map.has_key?(value)
      if map[value]
        ::Sequel.~(column => nil)
      else
        {column => nil}
      end
    end
  }
end

#lteq(column) ⇒ Object



71
72
73
# File 'lib/getto/repository/sequel/search.rb', line 71

def lteq(column)
  ->(value){ ::Sequel.lit("? <= ?", column, value) }
end

#or(wheres) ⇒ Object



98
99
100
101
102
103
104
105
106
# File 'lib/getto/repository/sequel/search.rb', line 98

def or(wheres)
  wheres = wheres.compact

  ->(value){
    unless wheres.empty?
      ::Sequel.|(*wheres.map{|w| w.call(value)})
    end
  }
end

#search(column, &block) ⇒ Object



114
115
116
117
118
# File 'lib/getto/repository/sequel/search.rb', line 114

def search(column,&block)
  if @query.has_key?(column.to_sym)
    @where << block.call(@query[column.to_sym])
  end
end