Class: Yapt::Filter
- Inherits:
-
Object
- Object
- Yapt::Filter
- Defined in:
- lib/yapt/filter.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#val ⇒ Object
readonly
Returns the value of attribute val.
Class Method Summary collapse
Instance Method Summary collapse
- #filter? ⇒ Boolean
-
#initialize(a, b = nil) ⇒ Filter
constructor
A new instance of Filter.
- #keyword? ⇒ Boolean
- #to_filter ⇒ Object
Constructor Details
#initialize(a, b = nil) ⇒ Filter
Returns a new instance of Filter.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/yapt/filter.rb', line 22 def initialize(a,b=nil) if b @key, @val = a.to_s, b.to_s else k, v = a.split(/[:=]/) v ? (@key, @val = k, v) : @val = k end clean_key! clean_val! end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
21 22 23 |
# File 'lib/yapt/filter.rb', line 21 def key @key end |
#val ⇒ Object (readonly)
Returns the value of attribute val.
21 22 23 |
# File 'lib/yapt/filter.rb', line 21 def val @val end |
Class Method Details
.parse(args) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/yapt/filter.rb', line 5 def self.parse(args) args.inject({filter: ""}) do |query, arg| filter = new(arg) if filter.filter? query[:filter] += "#{filter.to_filter} " else query[filter.key] = filter.val end query end end |
Instance Method Details
#filter? ⇒ Boolean
17 18 19 |
# File 'lib/yapt/filter.rb', line 17 def filter? not %w(limit offset).include?(key) end |
#keyword? ⇒ Boolean
33 34 35 |
# File 'lib/yapt/filter.rb', line 33 def keyword? !key end |
#to_filter ⇒ Object
37 38 39 |
# File 'lib/yapt/filter.rb', line 37 def to_filter keyword? ? val : coloned end |