Class: Getto::Repository::Sequel::Search::Where
- Inherits:
-
Object
- Object
- Getto::Repository::Sequel::Search::Where
- Defined in:
- lib/getto/repository/sequel/search.rb
Instance Method Summary collapse
- #cont(column) ⇒ Object
- #cont_as_hira(column) ⇒ Object
- #cont_as_kana(column) ⇒ Object
- #cont_hira_or_kana(column) ⇒ Object
- #eq(column) ⇒ Object
- #in(&query) ⇒ Object
-
#initialize(query:, where:) ⇒ Where
constructor
A new instance of Where.
- #is_not_null(column, map) ⇒ Object
- #or(wheres) ⇒ Object
- #search(column, &block) ⇒ Object
Constructor Details
#initialize(query:, where:) ⇒ Where
Returns a new instance of Where.
101 102 103 104 |
# File 'lib/getto/repository/sequel/search.rb', line 101 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 |
#in(&query) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/getto/repository/sequel/search.rb', line 80 def in(&query) ->(value){ where = value.map(&query).compact unless where.empty? ::Sequel.|(*where) end } end |
#is_not_null(column, map) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/getto/repository/sequel/search.rb', line 67 def is_not_null(column,map) ->(value){ if map.has_key?(value) if map[value] ::Sequel.~(column => nil) else {column => nil} end end } end |
#or(wheres) ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'lib/getto/repository/sequel/search.rb', line 90 def or(wheres) wheres = wheres.compact ->(value){ unless wheres.empty? ::Sequel.|(*wheres.map{|w| w.call(value)}) end } end |
#search(column, &block) ⇒ Object
106 107 108 109 110 |
# File 'lib/getto/repository/sequel/search.rb', line 106 def search(column,&block) if @query.has_key?(column.to_sym) @where << block.call(@query[column.to_sym]) end end |