Class: Sieve::Condition
- Inherits:
-
Object
- Object
- Sieve::Condition
- Defined in:
- lib/sieve-parser/condition.rb
Overview
This class contains the attributes of conditions/tests
Instance Attribute Summary collapse
-
#arg1 ⇒ Object
Returns the value of attribute arg1.
-
#arg2 ⇒ Object
Returns the value of attribute arg2.
-
#comparator ⇒ Object
Returns the value of attribute comparator.
-
#not ⇒ Object
Returns the value of attribute not.
-
#test ⇒ Object
Returns the value of attribute test.
-
#text ⇒ Object
Returns the value of attribute text.
-
#type ⇒ Object
Returns the value of attribute type.
-
#type_value ⇒ Object
Returns the value of attribute type_value.
Class Method Summary collapse
-
.parse_all(text) ⇒ Array(Contition)
Return a array of conditions after parse the text the text of conditions are splited by ‘,’.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Condition
constructor
Create Condition object by text of condition or params.
-
#to_s ⇒ string
Return a text of action.
Constructor Details
#initialize(params = {}) ⇒ Condition
Example: header :contains “Subject” “teste”
Create Condition object by text of condition or params
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/sieve-parser/condition.rb', line 18 def initialize params={} @text = params[:text] @test=params[:test] @not=params[:not] @arg1=params[:arg1] @arg2=params[:arg2] @type= params[:type] @comparator= params[:comparator] ? params[:comparator] : "i;ascii-numeric" parse unless @text.nil? end |
Instance Attribute Details
#arg1 ⇒ Object
Returns the value of attribute arg1.
6 7 8 |
# File 'lib/sieve-parser/condition.rb', line 6 def arg1 @arg1 end |
#arg2 ⇒ Object
Returns the value of attribute arg2.
6 7 8 |
# File 'lib/sieve-parser/condition.rb', line 6 def arg2 @arg2 end |
#comparator ⇒ Object
Returns the value of attribute comparator.
6 7 8 |
# File 'lib/sieve-parser/condition.rb', line 6 def comparator @comparator end |
#not ⇒ Object
Returns the value of attribute not.
6 7 8 |
# File 'lib/sieve-parser/condition.rb', line 6 def not @not end |
#test ⇒ Object
Returns the value of attribute test.
6 7 8 |
# File 'lib/sieve-parser/condition.rb', line 6 def test @test end |
#text ⇒ Object
Returns the value of attribute text.
6 7 8 |
# File 'lib/sieve-parser/condition.rb', line 6 def text @text end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/sieve-parser/condition.rb', line 6 def type @type end |
#type_value ⇒ Object
Returns the value of attribute type_value.
6 7 8 |
# File 'lib/sieve-parser/condition.rb', line 6 def type_value @type_value end |
Class Method Details
.parse_all(text) ⇒ Array(Contition)
Example: header :contains “From” “all”, header :contains “aaaaa” “333”
Return a array of conditions after parse the text the text of conditions are splited by ‘,’
34 35 36 37 38 39 40 41 |
# File 'lib/sieve-parser/condition.rb', line 34 def self.parse_all(text) contitions = [] #text.scan(/([\s\w:]*\"\S+\"\s\"[\sa-zA-Z0-9,\.\-\@ÁÀÃÂÇÉÈÊÍÌÓÒÔÕÚÙÜÑáàãâçéèêíìóòôõúùüñ]*\")/).each do |item| text.split_where(value:",",outside:'"').each do |item| contitions << self.new(text:item.strip) end contitions end |
Instance Method Details
#to_s ⇒ string
Return a text of action
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/sieve-parser/condition.rb', line 45 def to_s text ="" { 'not'=>@not, 'test'=>@test, 'type'=>@type, 'type_value'=>@type_value, 'comparator_name'=>(":comparator" if [":count", ":value"].index(@type)), 'comparator'=>(@comparator if [":count", ":value"].index(@type)), 'arg1'=>@arg1, 'arg2'=>@arg2 }.each do |name, item| if ['arg1','arg2'].index(name) text += "\"#{item}\" " unless item.nil? else text += "#{item} " unless item.nil? end end text[text.length-1] = "" text end |