Class: Hiiro::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/hiiro/tasks.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, tree: nil, session: nil, color_index: nil, **_) ⇒ Task

Returns a new instance of Task.



1464
1465
1466
1467
1468
1469
# File 'lib/hiiro/tasks.rb', line 1464

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_indexObject (readonly)

Returns the value of attribute color_index.



1462
1463
1464
# File 'lib/hiiro/tasks.rb', line 1462

def color_index
  @color_index
end

#nameObject (readonly)

Returns the value of attribute name.



1462
1463
1464
# File 'lib/hiiro/tasks.rb', line 1462

def name
  @name
end

#session_nameObject (readonly)

Returns the value of attribute session_name.



1462
1463
1464
# File 'lib/hiiro/tasks.rb', line 1462

def session_name
  @session_name
end

#tree_nameObject (readonly)

Returns the value of attribute tree_name.



1462
1463
1464
# File 'lib/hiiro/tasks.rb', line 1462

def tree_name
  @tree_name
end

Instance Method Details

#==(other) ⇒ Object



1500
1501
1502
# File 'lib/hiiro/tasks.rb', line 1500

def ==(other)
  other.is_a?(Task) && name == other.name
end

#branchObject



1492
1493
1494
# File 'lib/hiiro/tasks.rb', line 1492

def branch
  tree&.branch
end

#display_data(scope: :task, environment:) ⇒ Object



1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
# File 'lib/hiiro/tasks.rb', line 1516

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_nameObject



1471
1472
1473
1474
# File 'lib/hiiro/tasks.rb', line 1471

def parent_name
  return nil unless subtask?
  name.split('/').first
end

#pathObject



1496
1497
1498
# File 'lib/hiiro/tasks.rb', line 1496

def path
  tree&.path
end

#short_nameObject



1476
1477
1478
# File 'lib/hiiro/tasks.rb', line 1476

def short_name
  subtask? ? name.split('/', 2).last : name
end

#subtask?Boolean

Returns:

  • (Boolean)


1480
1481
1482
# File 'lib/hiiro/tasks.rb', line 1480

def subtask?
  name.include?('/')
end

#to_hObject



1508
1509
1510
1511
1512
1513
1514
# File 'lib/hiiro/tasks.rb', line 1508

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_sObject



1504
1505
1506
# File 'lib/hiiro/tasks.rb', line 1504

def to_s
  name
end

#top_level?Boolean

Returns:

  • (Boolean)


1484
1485
1486
# File 'lib/hiiro/tasks.rb', line 1484

def top_level?
  !subtask?
end

#treeObject



1488
1489
1490
# File 'lib/hiiro/tasks.rb', line 1488

def tree
  @tree ||= Environment.current&.find_tree(tree_name)
end