Class: Sieve::Action

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

Overview

This class contains the attributes of action

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text = nil) ⇒ Action

Note:

Example: fileinto :copy “INBOX.lixo”

Create Action object by text of action

Parameters:

  • text (string) (defaults to: nil)

    of action



14
15
16
17
18
19
20
# File 'lib/sieve-parser/action.rb', line 14

def initialize(text=nil)
  @text = text
  @type=nil
  @copy=nil
  @target=nil
  parse unless @text.nil?
end

Instance Attribute Details

#copyObject

Returns the value of attribute copy.



7
8
9
# File 'lib/sieve-parser/action.rb', line 7

def copy
  @copy
end

#targetObject

Returns the value of attribute target.



7
8
9
# File 'lib/sieve-parser/action.rb', line 7

def target
  @target
end

#textObject

Returns the value of attribute text.



7
8
9
# File 'lib/sieve-parser/action.rb', line 7

def text
  @text
end

#typeObject

Returns the value of attribute type.



7
8
9
# File 'lib/sieve-parser/action.rb', line 7

def type
  @type
end

Class Method Details

.parse_all(text) ⇒ Array(Action)

Note:

Example: fileinto “INBOX”; fileinto :copy “INBOX.lixo”; stop;

Return a array of actions after parse the text

Parameters:

  • text (string)

    of actions

Returns:

  • (Array(Action))

    array of Actions



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/sieve-parser/action.rb', line 29

def self.parse_all(text)
  lines = text.scan(/^[\s]*(.+;)$|^[\s]*(.+\n\S+.*;\s*.*\n\.\n\;)/)
  actions = []
  lines.each do |line|
    if !line[0].nil?
      actions << self.new(line[0])
    else
      actions << Sieve::Vacation.parse_text(line[1])
    end
  end
  actions
end

Instance Method Details

#to_sstring

Return a text of action

Returns:

  • (string)

    text of action



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sieve-parser/action.rb', line 44

def to_s
  text =""
  {'type'=>@type, 'copy'=>(@copy) ? ":copy" : nil, 'target'=>@target}.each do |name,item|
    if ['target'].index(name)
      text += "\"#{item}\" " unless item.nil?
    else
      text += "#{item} " unless item.nil?
    end

  end
  text[text.length-1] = ";" if text.length > 0
  text
end