Class: Tempo::Model::Project
Instance Attribute Summary collapse
Attributes inherited from Composite
#children, #parent
Attributes inherited from Base
#id
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Composite
#<<, delete, #remove_child, #report_branches, report_trees
Methods inherited from Base
#delete, delete, file, find, find_by_id, id_counter, ids, index, instances_have_attributes?, method_missing, read_from_file, respond_to?, run_find_by_method, run_sort_by_method, save_to_file
Constructor Details
#initialize(options = {}) ⇒ Project
Returns a new instance of Project.
38
39
40
41
42
43
44
45
|
# File 'lib/tempo/models/project.rb', line 38
def initialize(options={})
super options
@title = options.fetch(:title, "new project")
@tags = []
tag options.fetch(:tags, [])
current = options.fetch(:current, false)
self.class.current = self if current
end
|
Instance Attribute Details
Returns the value of attribute tags.
7
8
9
|
# File 'lib/tempo/models/project.rb', line 7
def tags
@tags
end
|
#title ⇒ Object
Returns the value of attribute title.
6
7
8
|
# File 'lib/tempo/models/project.rb', line 6
def title
@title
end
|
Class Method Details
.current(instance = nil) ⇒ Object
12
13
14
|
# File 'lib/tempo/models/project.rb', line 12
def current(instance=nil)
@current
end
|
.current=(instance) ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/tempo/models/project.rb', line 16
def current=(instance)
if instance.class == self
@current = instance
else
raise ArgumentError
end
end
|
.include?(title) ⇒ Boolean
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/tempo/models/project.rb', line 24
def include?(title)
return false if index.empty?
matches = find_by_title(title)
return false if matches.empty?
matches.each do |match|
return true if match.title == title
end
false
end
|
Instance Method Details
#current? ⇒ Boolean
47
48
49
|
# File 'lib/tempo/models/project.rb', line 47
def current?
self.class.current == self
end
|
#freeze_dry ⇒ Object
record the active project by adding current = true
52
53
54
55
56
57
58
|
# File 'lib/tempo/models/project.rb', line 52
def freeze_dry
record = super
if self.class.current == self
record[:current] = true
end
record
end
|
#tag(tags) ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/tempo/models/project.rb', line 60
def tag(tags)
return unless tags and tags.kind_of? Array
tags.each do |tag|
tag.split.each {|t| @tags << t if ! @tags.include? t }
end
@tags.sort!
end
|
#to_s ⇒ Object
75
76
77
|
# File 'lib/tempo/models/project.rb', line 75
def to_s
puts "id: #{id}, title: #{title}, tags: #{tags}"
end
|
#untag(tags) ⇒ Object
68
69
70
71
72
73
|
# File 'lib/tempo/models/project.rb', line 68
def untag(tags)
return unless tags and tags.kind_of? Array
tags.each do |tag|
tag.split.each {|t| @tags.delete t }
end
end
|