Class: Rtodotxt::List

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(list) ⇒ List

Returns a new instance of List.



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

def initialize list
  super self.class.gen_list_from_string list
end

Class Method Details

.gen_list_from_string(str) ⇒ Object



24
25
26
27
28
# File 'lib/rtodotxt.rb', line 24

def self.gen_list_from_string str
  str.split( "\n" ).map! do |line| 
    Todo.new line unless line.empty?
  end
end

Instance Method Details

Join the todo text together to return the list



18
19
20
21
22
# File 'lib/rtodotxt.rb', line 18

def print
  str = self.map { |t| t.text }.join "\n"
  # the result must end with a newline!
  str << "\n"
end

#read(str) ⇒ Object

Split a string by each line and generate an array of todos



13
14
15
# File 'lib/rtodotxt.rb', line 13

def read str
  super self.class.gen_list_from_string str
end