Class: REM::E

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

Overview

The Reminder collection object.

Instance Method Summary collapse

Constructor Details

#initialize(k) ⇒ E

Reminder collection k.



6
7
8
9
10
# File 'lib/remind/remind.rb', line 6

def initialize k
  @id = k
  @r = Hash.new { |h,k| h[k] = R.new(k) }
  clear!
end

Instance Method Details

#[](k) ⇒ Object

get Reminder from collection.



15
16
17
18
19
# File 'lib/remind/remind.rb', line 15

def [] k
  @rem << k
  @rem.uniq
  @r[k]
end

#clear!Object

Clear Reminder collection.



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

def clear!
  @rem = []
end

#get(a) ⇒ Object

get Reminder collection with arguments a.



22
23
24
25
26
27
# File 'lib/remind/remind.rb', line 22

def get a
  if !File.exist?("rem/#{@id}.rem")
    File.open("rem/#{@id}.rem",'w') { |f| f.write(""); }
  end
  `rem #{a} rem/#{@id}.rem`.split("\n\n")
end

#idObject

Reminder collection id.



12
# File 'lib/remind/remind.rb', line 12

def id; @id; end

#to_remObject

Reminder collection to string.



35
36
37
38
39
# File 'lib/remind/remind.rb', line 35

def to_rem
  a = [];
  @rem.each { |e| a << @r[e].to_rem }
  return a.join("\n")
end

#to_rem!(h = {}) ⇒ Object

Write Reminder collection to file. h[:append] append. (default: write)



43
44
45
46
47
48
49
50
51
52
# File 'lib/remind/remind.rb', line 43

def to_rem! h={}
  if !Dir.exist? "rem"
    Dir.mkdir("rem")
  end
  if h[:append] == true
    File.open("rem/#{@id}.rem",'a') { |f| f.write(to_rem); }
  else
    File.open("rem/#{@id}.rem",'w') { |f| f.write(to_rem); }
  end
end