Class: Sieve::Action
- Inherits:
-
Object
- Object
- Sieve::Action
- Defined in:
- lib/sieve-parser/action.rb
Overview
This class contains the attributes of action
Instance Attribute Summary collapse
-
#copy ⇒ Object
Returns the value of attribute copy.
-
#target ⇒ Object
Returns the value of attribute target.
-
#text ⇒ Object
Returns the value of attribute text.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
-
.parse_all(text) ⇒ Array(Action)
Return a array of actions after parse the text.
Instance Method Summary collapse
-
#initialize(text = nil) ⇒ Action
constructor
Create Action object by text of action.
-
#to_s ⇒ string
Return a text of action.
Constructor Details
#initialize(text = nil) ⇒ Action
Note:
Example: fileinto :copy “INBOX.lixo”
Create Action object by text 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
#copy ⇒ Object
Returns the value of attribute copy.
7 8 9 |
# File 'lib/sieve-parser/action.rb', line 7 def copy @copy end |
#target ⇒ Object
Returns the value of attribute target.
7 8 9 |
# File 'lib/sieve-parser/action.rb', line 7 def target @target end |
#text ⇒ Object
Returns the value of attribute text.
7 8 9 |
# File 'lib/sieve-parser/action.rb', line 7 def text @text end |
#type ⇒ Object
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
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_s ⇒ string
Return a 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 |