Class: Torque::FieldFilter
- Inherits:
-
Object
- Object
- Torque::FieldFilter
- Defined in:
- lib/torque/field_filter.rb
Overview
Parses and stores a field filter for stories
Instance Attribute Summary collapse
-
#contents ⇒ Object
readonly
The contents of the filter.
-
#field ⇒ Object
readonly
The field that the FieldFilter filters over.
Instance Method Summary collapse
-
#eval(story) ⇒ Object
Returns true if the filter includes the story, false if it excludes it.
-
#initialize(field, contents = "") ⇒ FieldFilter
constructor
The contents should be a list of values speparated by “,” or “+”, where AND is signified by “+” and OR is signified by “,”, and “+” has a higher precedence than “,”.
-
#to_s ⇒ Object
Returns a string representation of the FieldFilter.
Constructor Details
#initialize(field, contents = "") ⇒ FieldFilter
The contents should be a list of values speparated by “,” or “+”, where AND is signified by “+” and OR is signified by “,”, and “+” has a higher precedence than “,”. For example,
“ios+android,ios+web”
translates to
(ios AND android) OR (ios AND web)
An :owner filter with no spaces in it will filter separately by first/middle/last name. For instance, “Adam” would match “Adam Barnes” or “John Adam Smith” or “Joe Quincy Adam”.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/torque/field_filter.rb', line 35 def initialize(field, contents="") @field = field @contents = contents # Represents evaluator as a 2-level array, @evaluator # # (ios AND android) OR (ios AND web) <=> # [["ios", "android"], ["ios", "web"]] parse_contents end |
Instance Attribute Details
#contents ⇒ Object (readonly)
The contents of the filter
13 14 15 |
# File 'lib/torque/field_filter.rb', line 13 def contents @contents end |
#field ⇒ Object (readonly)
The field that the FieldFilter filters over
9 10 11 |
# File 'lib/torque/field_filter.rb', line 9 def field @field end |
Instance Method Details
#eval(story) ⇒ Object
Returns true if the filter includes the story, false if it excludes it
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/torque/field_filter.rb', line 48 def eval(story) # Determines the field to evaluate story_field = nil if @field == :label story_field = story.labels elsif @field == :owner story_field = story.owner elsif @field == :type story_field = story.type else # Invalid filter return true end # Evaluates the story's field or_eval = false @evaluator.each do |or_element| and_eval = true or_element.each do |and_element| if @field == :label and_eval &&= (story_field.member? and_element) elsif @field == :owner # Special case: "owner" filter # If the filter element has no spaces in it... # Then it is assumed to be a first/middle/last name, not a full name if !and_element.match(" ") and_eval &&= (story_field.split(" ").member? and_element) else and_eval &&= (story_field == and_element) end else # @field == :type and_eval &&= (story_field == and_element) end end or_eval ||= and_eval end or_eval end |
#to_s ⇒ Object
Returns a string representation of the FieldFilter
100 101 102 |
# File 'lib/torque/field_filter.rb', line 100 def to_s "#{@field} = #{@contents}" end |