Class: SugoiAliasesUpdator::AliasesParser
- Inherits:
-
Object
- Object
- SugoiAliasesUpdator::AliasesParser
- Defined in:
- lib/sugoi_aliases_updator/aliases_parser.rb
Instance Attribute Summary collapse
-
#changed_labels ⇒ Object
Returns the value of attribute changed_labels.
Instance Method Summary collapse
- #add(target_email, to) ⇒ Object
-
#initialize(filepath) ⇒ AliasesParser
constructor
A new instance of AliasesParser.
- #list(target_email) ⇒ Object
- #render! ⇒ Object
- #rm(target_email, from) ⇒ Object
Constructor Details
#initialize(filepath) ⇒ AliasesParser
Returns a new instance of AliasesParser.
6 7 8 9 |
# File 'lib/sugoi_aliases_updator/aliases_parser.rb', line 6 def initialize(filepath) @native_lines = File.readlines(filepath) @changed_labels = [] end |
Instance Attribute Details
#changed_labels ⇒ Object
Returns the value of attribute changed_labels.
4 5 6 |
# File 'lib/sugoi_aliases_updator/aliases_parser.rb', line 4 def changed_labels @changed_labels end |
Instance Method Details
#add(target_email, to) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/sugoi_aliases_updator/aliases_parser.rb', line 11 def add(target_email, to) check_labels!(to) to.each do |x| unless label_mails_hash[x].include?(target_email) label_mails_hash[x].push(target_email) @changed_labels << x end end render! end |
#list(target_email) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/sugoi_aliases_updator/aliases_parser.rb', line 43 def list(target_email) finded = [] label_mails_hash.each do |key, value| finded.push(key) if value.include?(target_email) end finded.join(',') end |
#render! ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/sugoi_aliases_updator/aliases_parser.rb', line 51 def render! new_lines = [] @native_lines.each do |line| line_paser = LineParser.new(line) if line_paser.is_aliaes_line && @changed_labels.include?(line_paser.label) line = "#{line_paser.label}:#{line_paser.margin}#{label_mails_hash[line_paser.label].join(", ")}\n" end new_lines << line end new_lines.join end |
#rm(target_email, from) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/sugoi_aliases_updator/aliases_parser.rb', line 22 def rm(target_email, from) if ['ALL'] == from label_mails_hash.each do |label, emails| if emails.include?(target_email) label_mails_hash[label].delete(target_email) @changed_labels << label end end return render! end check_labels!(from) from.each do |label| if label_mails_hash[label].include?(target_email) label_mails_hash[label].delete(target_email) @changed_labels << label end end render! end |