Class: Tempo::Model::Project

Inherits:
Composite show all
Defined in:
lib/tempo/models/project.rb

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

add_id, add_to_index, #delete, delete, file, find, find_by_id, id_counter, ids, increase_id_counter, index, method_missing, next_id, read_from_file, run_find_by_method, run_sort_by_method, save_to_file

Constructor Details

#initialize(options = {}) ⇒ Project

Returns a new instance of Project.



32
33
34
35
36
37
38
39
# File 'lib/tempo/models/project.rb', line 32

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

#tagsObject (readonly)

Returns the value of attribute tags.



5
6
7
# File 'lib/tempo/models/project.rb', line 5

def tags
  @tags
end

#titleObject

Returns the value of attribute title.



4
5
6
# File 'lib/tempo/models/project.rb', line 4

def title
  @title
end

Class Method Details

.current(instance = nil) ⇒ Object



10
11
12
# File 'lib/tempo/models/project.rb', line 10

def current( instance=nil )
  @current
end

.current=(instance) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/tempo/models/project.rb', line 14

def current=( instance )
  if instance.class == self
    @current = instance
  else
    raise ArgumentError
  end
end

.include?(title) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
# File 'lib/tempo/models/project.rb', line 22

def include?( title )
  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

Returns:

  • (Boolean)


41
42
43
# File 'lib/tempo/models/project.rb', line 41

def current?
  self.class.current == self
end

#freeze_dryObject



45
46
47
48
49
50
51
# File 'lib/tempo/models/project.rb', line 45

def freeze_dry
  record = super
  if self.class.current == self
    record[:current] = true
  end
  record
end

#tag(tags) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/tempo/models/project.rb', line 53

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_sObject



68
69
70
# File 'lib/tempo/models/project.rb', line 68

def to_s
  puts "id: #{id}, title: #{title}, tags: #{tags}"
end

#untag(tags) ⇒ Object



61
62
63
64
65
66
# File 'lib/tempo/models/project.rb', line 61

def untag( tags )
  return unless tags and tags.kind_of? Array
  tags.each do |tag|
    tag.split.each {|t| @tags.delete t }
  end
end