Class: Swallow::Email

Inherits:
Object
  • Object
show all
Defined in:
lib/email.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Email

Returns a new instance of Email.



11
12
13
14
15
# File 'lib/email.rb', line 11

def initialize(filename)
    @filename = filename
    path_parts = filename.split(/\//)
    parse_filename(path_parts[-1])
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



9
10
11
# File 'lib/email.rb', line 9

def filename
  @filename
end

#hostObject

Returns the value of attribute host.



8
9
10
# File 'lib/email.rb', line 8

def host
  @host
end

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/email.rb', line 8

def id
  @id
end

#orderObject

Returns the value of attribute order.



8
9
10
# File 'lib/email.rb', line 8

def order
  @order
end

#weird_idObject

Returns the value of attribute weird_id.



8
9
10
# File 'lib/email.rb', line 8

def weird_id
  @weird_id
end

Instance Method Details

#deleteObject



46
47
48
# File 'lib/email.rb', line 46

def delete
    File.delete(@filename)
end

#mark_readObject



34
35
36
# File 'lib/email.rb', line 34

def mark_read
    # modify filename to "S" on end
end

#move_to(folder) ⇒ Object



38
39
40
# File 'lib/email.rb', line 38

def move_to(folder)
    File.move(@filename, folder, true)
end

#newer_than?(limit) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/email.rb', line 22

def newer_than?(limit)
    File.open(@filename).newer_than?(Date.today - limit)
end

#older_than?(limit) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/email.rb', line 26

def older_than?(limit)
    File.open(@filename).older_than?(Date.today - limit)
end

#parse_filename(file) ⇒ Object



17
18
19
20
# File 'lib/email.rb', line 17

def parse_filename(file)
    uppername, @order, @read = file.split(/,/)
    @id, @weird_id, @host = uppername.split(/\./)
end

#read?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/email.rb', line 30

def read?
    @read == "S"
end

#to_sObject



42
43
44
# File 'lib/email.rb', line 42

def to_s
    File.open(@filename).read
end