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.



4
5
6
# File 'lib/jirametrics/status_collection.rb', line 4

def initialize
  @list = []
end

Instance Method Details

#<<(arg) ⇒ Object



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

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

#clearObject



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

def clear = @list.clear

#collect(&block) ⇒ Object



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

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

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



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

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

#each(&block) ⇒ Object



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

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

#empty?Boolean

Returns:

  • (Boolean)


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

def empty? = @list.empty?

#expand_statuses(names_or_ids) ⇒ Object



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

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 "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



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/jirametrics/status_collection.rb', line 8

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

  @list.collect 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.compact
end

#find(&block) ⇒ Object



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

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

#find_by_name(name) ⇒ Object



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

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

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



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

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

#select(&block) ⇒ Object



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

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

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



44
45
46
# File 'lib/jirametrics/status_collection.rb', line 44

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