Class: Hiiro::Task
- Inherits:
-
Object
- Object
- Hiiro::Task
- Defined in:
- lib/hiiro/tasks.rb
Instance Attribute Summary collapse
-
#color_index ⇒ Object
readonly
Returns the value of attribute color_index.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#session_name ⇒ Object
readonly
Returns the value of attribute session_name.
-
#tree_name ⇒ Object
readonly
Returns the value of attribute tree_name.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #absolute_tree? ⇒ Boolean
- #branch ⇒ Object
- #display_data(scope: :task, environment:) ⇒ Object
-
#initialize(name:, tree: nil, session: nil, color_index: nil, **_) ⇒ Task
constructor
A new instance of Task.
- #parent_name ⇒ Object
- #path ⇒ Object
- #short_name ⇒ Object
- #subtask? ⇒ Boolean
- #to_h ⇒ Object
- #to_s ⇒ Object
- #top_level? ⇒ Boolean
- #tree ⇒ Object
Constructor Details
#initialize(name:, tree: nil, session: nil, color_index: nil, **_) ⇒ Task
Returns a new instance of Task.
1529 1530 1531 1532 1533 1534 |
# File 'lib/hiiro/tasks.rb', line 1529 def initialize(name:, tree: nil, session: nil, color_index: nil, **_) @name = name @tree_name = tree @session_name = session || name @color_index = color_index end |
Instance Attribute Details
#color_index ⇒ Object (readonly)
Returns the value of attribute color_index.
1527 1528 1529 |
# File 'lib/hiiro/tasks.rb', line 1527 def color_index @color_index end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
1527 1528 1529 |
# File 'lib/hiiro/tasks.rb', line 1527 def name @name end |
#session_name ⇒ Object (readonly)
Returns the value of attribute session_name.
1527 1528 1529 |
# File 'lib/hiiro/tasks.rb', line 1527 def session_name @session_name end |
#tree_name ⇒ Object (readonly)
Returns the value of attribute tree_name.
1527 1528 1529 |
# File 'lib/hiiro/tasks.rb', line 1527 def tree_name @tree_name end |
Instance Method Details
#==(other) ⇒ Object
1569 1570 1571 |
# File 'lib/hiiro/tasks.rb', line 1569 def ==(other) other.is_a?(Task) && name == other.name end |
#absolute_tree? ⇒ Boolean
1553 1554 1555 |
# File 'lib/hiiro/tasks.rb', line 1553 def absolute_tree? tree_name.to_s.start_with?('/') end |
#branch ⇒ Object
1561 1562 1563 |
# File 'lib/hiiro/tasks.rb', line 1561 def branch tree&.branch end |
#display_data(scope: :task, environment:) ⇒ Object
1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 |
# File 'lib/hiiro/tasks.rb', line 1585 def display_data(scope: :task, environment:) display_name = (scope == :subtask) ? short_name : name tree = environment.find_tree(tree_name) branch = tree&.branch || (tree&.detached? ? '(detached)' : '(none)') sname = session_name || '(none)' { name: display_name, tree: tree_name || '(none)', branch: "[#{branch}]", session: "(#{sname})" } end |
#parent_name ⇒ Object
1536 1537 1538 1539 |
# File 'lib/hiiro/tasks.rb', line 1536 def parent_name return nil unless subtask? name.split('/').first end |
#path ⇒ Object
1565 1566 1567 |
# File 'lib/hiiro/tasks.rb', line 1565 def path tree&.path end |
#short_name ⇒ Object
1541 1542 1543 |
# File 'lib/hiiro/tasks.rb', line 1541 def short_name subtask? ? name.split('/', 2).last : name end |
#subtask? ⇒ Boolean
1545 1546 1547 |
# File 'lib/hiiro/tasks.rb', line 1545 def subtask? name.include?('/') && !absolute_tree? end |
#to_h ⇒ Object
1577 1578 1579 1580 1581 1582 1583 |
# File 'lib/hiiro/tasks.rb', line 1577 def to_h h = { name: name } h[:tree] = tree_name if tree_name h[:session] = session_name if session_name != name h[:color_index] = color_index unless color_index.nil? h end |
#to_s ⇒ Object
1573 1574 1575 |
# File 'lib/hiiro/tasks.rb', line 1573 def to_s name end |
#top_level? ⇒ Boolean
1549 1550 1551 |
# File 'lib/hiiro/tasks.rb', line 1549 def top_level? !subtask? end |
#tree ⇒ Object
1557 1558 1559 |
# File 'lib/hiiro/tasks.rb', line 1557 def tree @tree ||= Environment.current&.find_tree(tree_name) end |