Class: StatusCollection

Inherits:
Object show all
Defined in:
lib/jirametrics/status_collection.rb

Instance Method Summary collapse

Constructor Details

#initializeStatusCollection

Returns a new instance of StatusCollection.



7
8
9
# File 'lib/jirametrics/status_collection.rb', line 7

def initialize
  @list = []
end

Instance Method Details

#<<(arg) ⇒ Object



67
# File 'lib/jirametrics/status_collection.rb', line 67

def <<(arg) = @list << arg

#clearObject



69
# File 'lib/jirametrics/status_collection.rb', line 69

def clear = @list.clear

#collect(&block) ⇒ Object



64
# File 'lib/jirametrics/status_collection.rb', line 64

def collect(&block) = @list.collect(&block)

#delete(object) ⇒ Object



70
# File 'lib/jirametrics/status_collection.rb', line 70

def delete(object) = @list.delete(object)

#done(including: nil, excluding: nil) ⇒ Object



55
56
57
# File 'lib/jirametrics/status_collection.rb', line 55

def done including: nil, excluding: nil
  filter_status_names category_name: 'Done', including: including, excluding: excluding
end

#each(&block) ⇒ Object



65
# File 'lib/jirametrics/status_collection.rb', line 65

def each(&block) = @list.each(&block)

#empty?Boolean

Returns:

  • (Boolean)


68
# File 'lib/jirametrics/status_collection.rb', line 68

def empty? = @list.empty?

#expand_statuses(names_or_ids) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/jirametrics/status_collection.rb', line 24

def expand_statuses names_or_ids
  result = []
  return result if names_or_ids.nil?

  names_or_ids = [names_or_ids] unless names_or_ids.is_a? Array

  names_or_ids.each do |name_or_id|
    status = @list.find { |s| s.name == name_or_id || s.id == name_or_id }
    if status.nil?
      if block_given?
        yield name_or_id
        next
      else
        all_status_names = @list.collect { |s| "#{s.name.inspect}:#{s.id.inspect}" }.uniq.sort.join(', ')
        raise StatusNotFoundError, "Status not found: \"#{name_or_id}\". Possible statuses are: #{all_status_names}"
      end
    end

    result << status
  end
  result
end

#filter_status_names(category_name:, including: nil, excluding: nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/jirametrics/status_collection.rb', line 11

def filter_status_names category_name:, including: nil, excluding: nil
  including = expand_statuses including
  excluding = expand_statuses excluding

  @list.filter_map do |status|
    keep = status.category_name == category_name ||
      including.any? { |s| s.name == status.name }
    keep = false if excluding.any? { |s| s.name == status.name }

    status.name if keep
  end
end

#find(&block) ⇒ Object



63
# File 'lib/jirametrics/status_collection.rb', line 63

def find(&block)= @list.find(&block)

#find_by_name(name) ⇒ Object



59
60
61
# File 'lib/jirametrics/status_collection.rb', line 59

def find_by_name name
  find { |status| status.name == name }
end

#in_progress(including: nil, excluding: nil) ⇒ Object



51
52
53
# File 'lib/jirametrics/status_collection.rb', line 51

def in_progress including: nil, excluding: nil
  filter_status_names category_name: 'In Progress', including: including, excluding: excluding
end

#inspectObject



72
73
74
# File 'lib/jirametrics/status_collection.rb', line 72

def inspect
  "StatusCollection(#{@list.collect(&:inspect).join(', ')})"
end

#select(&block) ⇒ Object



66
# File 'lib/jirametrics/status_collection.rb', line 66

def select(&block) = @list.select(&block)

#todo(including: nil, excluding: nil) ⇒ Object



47
48
49
# File 'lib/jirametrics/status_collection.rb', line 47

def todo including: nil, excluding: nil
  filter_status_names category_name: 'To Do', including: including, excluding: excluding
end