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

delete, #delete, file, find, find_by_id, id_counter, ids, index, method_missing, 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.



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

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.



7
8
9
# File 'lib/tempo/models/project.rb', line 7

def tags
  @tags
end

#titleObject

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

Returns:

  • (Boolean)


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

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)


43
44
45
# File 'lib/tempo/models/project.rb', line 43

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

#freeze_dryObject

record the active project by adding current = true



48
49
50
51
52
53
54
# File 'lib/tempo/models/project.rb', line 48

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

#tag(tags) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/tempo/models/project.rb', line 56

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



71
72
73
# File 'lib/tempo/models/project.rb', line 71

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

#untag(tags) ⇒ Object



64
65
66
67
68
69
# File 'lib/tempo/models/project.rb', line 64

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