Class: Sieve::Condition

Inherits:
Object
  • Object
show all
Defined in:
lib/sieve-parser/condition.rb

Overview

This class contains the attributes of conditions/tests

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Condition

Note:

Example: header :contains “Subject” “teste”

Create Condition object by text of condition or params

Parameters:

  • (:text) (String)

    text of condition

  • (:test) (String)

    test of condition

  • (:not) (String)

    not of condition

  • (:arg1) (String)

    arg1 of condition

  • (:arg2) (String)

    arg2 of condition

  • (:type) (String)

    type of condition



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

#arg1Object

Returns the value of attribute arg1.



6
7
8
# File 'lib/sieve-parser/condition.rb', line 6

def arg1
  @arg1
end

#arg2Object

Returns the value of attribute arg2.



6
7
8
# File 'lib/sieve-parser/condition.rb', line 6

def arg2
  @arg2
end

#comparatorObject

Returns the value of attribute comparator.



6
7
8
# File 'lib/sieve-parser/condition.rb', line 6

def comparator
  @comparator
end

#notObject

Returns the value of attribute not.



6
7
8
# File 'lib/sieve-parser/condition.rb', line 6

def not
  @not
end

#testObject

Returns the value of attribute test.



6
7
8
# File 'lib/sieve-parser/condition.rb', line 6

def test
  @test
end

#textObject

Returns the value of attribute text.



6
7
8
# File 'lib/sieve-parser/condition.rb', line 6

def text
  @text
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/sieve-parser/condition.rb', line 6

def type
  @type
end

#type_valueObject

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)

Note:

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 ‘,’

Parameters:

  • text (string)

    of conditions

Returns:

  • (Array(Contition))

    array of Condition



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_sstring

Return a text of action

Returns:

  • (string)

    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