Class: Taskcmd::Project
- Inherits:
-
Object
- Object
- Taskcmd::Project
- 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
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#next_id ⇒ Object
readonly
Returns the value of attribute next_id.
-
#tasks ⇒ Object
readonly
Returns the value of attribute tasks.
Class Method Summary collapse
Instance Method Summary collapse
- #increment_next_id ⇒ Object
-
#initialize(name) ⇒ Project
constructor
A new instance of Project.
- #to_msgpack_ext ⇒ Object
Constructor Details
#initialize(name) ⇒ Project
Returns a new instance of Project.
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/taskcmd/project.rb', line 8 def name @name end |
#next_id ⇒ Object (readonly)
Returns the value of attribute next_id.
8 9 10 |
# File 'lib/taskcmd/project.rb', line 8 def next_id @next_id end |
#tasks ⇒ Object (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_id ⇒ Object
18 19 20 |
# File 'lib/taskcmd/project.rb', line 18 def increment_next_id @next_id += 1 end |
#to_msgpack_ext ⇒ Object
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 |