Class: Bronto::Filter
Instance Attribute Summary collapse
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#add_filter(*args) ⇒ Object
Accepts two or three arguments: 1.
-
#initialize ⇒ Filter
constructor
A new instance of Filter.
- #to_hash ⇒ Object
Constructor Details
#initialize ⇒ Filter
Returns a new instance of Filter.
8 9 10 |
# File 'lib/bronto/filter.rb', line 8 def initialize self.fields = {} end |
Instance Attribute Details
#fields ⇒ Object
Returns the value of attribute fields.
6 7 8 |
# File 'lib/bronto/filter.rb', line 6 def fields @fields end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/bronto/filter.rb', line 6 def type @type end |
Instance Method Details
#add_filter(*args) ⇒ Object
Accepts two or three arguments:
1. Field name
2. (optional) The operator to use (only available for certain fields; see the filter documentation).
3. Value
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bronto/filter.rb', line 21 def add_filter(*args) raise ArgumentError, "wrong number of arguments (#{args.length} for 2..3)" if args.length != 2 and args.length != 3 field = args.shift.to_sym self.fields[field] = [] unless self.fields.has_key?(field) if args.length == 1 self.fields[field] << args.first else self.fields[field] << { operator: args.first, value: args.last } end self end |
#to_hash ⇒ Object
12 13 14 15 |
# File 'lib/bronto/filter.rb', line 12 def to_hash hash = { type: type || "AND" } hash.merge(fields) end |