Class: Taskcmd::Project

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

Overview

Project is a collection of similar tasks.

Constant Summary collapse

NAME_PATTERN =
/\A[a-z]+{3,10}\z/.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Project

Returns a new instance of Project.

Raises:



10
11
12
13
14
15
16
# File 'lib/taskcmd/project.rb', line 10

def initialize(name)
  raise Taskcmd::Error, 'invalid project name' unless name.match?(NAME_PATTERN)

  @name = name
  @tasks = []
  @next_id = 1
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#next_idObject (readonly)

Returns the value of attribute next_id.



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

def next_id
  @next_id
end

#tasksObject (readonly)

Returns the value of attribute tasks.



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

def tasks
  @tasks
end

Class Method Details

.from_msgpack_ext(data) ⇒ Object



30
31
32
33
34
35
# File 'lib/taskcmd/project.rb', line 30

def self.from_msgpack_ext(data)
  unpacked = MessagePack.unpack(data)
  new(unpacked[:name]).tap do |obj|
    unpacked.each { |k, v| obj.instance_variable_set("@#{k}", v) }
  end
end

Instance Method Details

#increment_next_idObject



18
19
20
# File 'lib/taskcmd/project.rb', line 18

def increment_next_id
  @next_id += 1
end

#to_msgpack_extObject



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

def to_msgpack_ext
  {
    name: name,
    tasks: tasks,
    next_id: next_id,
  }.to_msgpack
end