Class: StatusCollection
- Inherits:
-
Object
- Object
- StatusCollection
- Defined in:
- lib/jirametrics/status_collection.rb
Instance Attribute Summary collapse
-
#example_issue_key ⇒ Object
readonly
Returns the value of attribute example_issue_key.
-
#fabricated_statuses ⇒ Object
readonly
Returns the value of attribute fabricated_statuses.
-
#historical_status_mappings ⇒ Object
readonly
Returns the value of attribute historical_status_mappings.
Instance Method Summary collapse
- #<<(arg) ⇒ Object
- #clear ⇒ Object
- #collect(&block) ⇒ Object
- #delete(object) ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
- #fabricate_status_for(id:, name:, example_issue_key: nil) ⇒ Object
- #find(&block) ⇒ Object
- #find_all_by_name(identifier) ⇒ Object
- #find_all_categories ⇒ Object
- #find_all_categories_by_name(identifier) ⇒ Object
-
#find_by_id(id) ⇒ Object
Return the status matching this id or nil if it can't be found.
- #find_by_id!(id) ⇒ Object
-
#initialize ⇒ StatusCollection
constructor
A new instance of StatusCollection.
- #inspect ⇒ Object
- #parse_name_id(name) ⇒ Object
- #select(&block) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ StatusCollection
Returns a new instance of StatusCollection.
9 10 11 12 13 14 |
# File 'lib/jirametrics/status_collection.rb', line 9 def initialize @list = [] @historical_status_mappings = {} # 'name:id' => category @fabricated_statuses = [] @example_issue_key = nil end |
Instance Attribute Details
#example_issue_key ⇒ Object (readonly)
Returns the value of attribute example_issue_key.
7 8 9 |
# File 'lib/jirametrics/status_collection.rb', line 7 def example_issue_key @example_issue_key end |
#fabricated_statuses ⇒ Object (readonly)
Returns the value of attribute fabricated_statuses.
7 8 9 |
# File 'lib/jirametrics/status_collection.rb', line 7 def fabricated_statuses @fabricated_statuses end |
#historical_status_mappings ⇒ Object (readonly)
Returns the value of attribute historical_status_mappings.
7 8 9 |
# File 'lib/jirametrics/status_collection.rb', line 7 def historical_status_mappings @historical_status_mappings end |
Instance Method Details
#<<(arg) ⇒ Object
80 |
# File 'lib/jirametrics/status_collection.rb', line 80 def <<(arg) = @list << arg |
#clear ⇒ Object
82 |
# File 'lib/jirametrics/status_collection.rb', line 82 def clear = @list.clear |
#collect(&block) ⇒ Object
76 |
# File 'lib/jirametrics/status_collection.rb', line 76 def collect(&block) = @list.collect(&block) |
#delete(object) ⇒ Object
83 |
# File 'lib/jirametrics/status_collection.rb', line 83 def delete(object) = @list.delete(object) |
#each(&block) ⇒ Object
78 |
# File 'lib/jirametrics/status_collection.rb', line 78 def each(&block) = @list.each(&block) |
#empty? ⇒ Boolean
81 |
# File 'lib/jirametrics/status_collection.rb', line 81 def empty? = @list.empty? |
#fabricate_status_for(id:, name:, example_issue_key: nil) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/jirametrics/status_collection.rb', line 93 def fabricate_status_for id:, name:, example_issue_key: nil @example_issue_key ||= example_issue_key category = @historical_status_mappings["#{name.inspect}:#{id.inspect}"] category = guess_category_by_name(name) if category.nil? status = Status.new( name: name, id: id, category_name: category.name, category_id: category.id, category_key: category.key, artificial: true ) @list << status @fabricated_statuses << status status end |
#find(&block) ⇒ Object
77 |
# File 'lib/jirametrics/status_collection.rb', line 77 def find(&block) = @list.find(&block) |
#find_all_by_name(identifier) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/jirametrics/status_collection.rb', line 28 def find_all_by_name identifier name, id = parse_name_id identifier if id status = find_by_id id return [] if status.nil? if name && status.name != name raise "Specified status ID of #{id} does not match specified name #{name.inspect}. " \ "You might have meant one of these: #{self}." end [status] else @list.select { |status| status.name == name } end end |
#find_all_categories ⇒ Object
45 46 47 48 49 50 |
# File 'lib/jirametrics/status_collection.rb', line 45 def find_all_categories @list .collect(&:category) .uniq .sort_by(&:id) end |
#find_all_categories_by_name(identifier) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/jirametrics/status_collection.rb', line 63 def find_all_categories_by_name identifier key = nil id = nil if identifier.is_a? Symbol key = identifier.to_s else name, id = parse_name_id identifier end find_all_categories.select { |c| c.id == id || c.name == name || c.key == key } end |
#find_by_id(id) ⇒ Object
Return the status matching this id or nil if it can't be found.
17 18 19 |
# File 'lib/jirametrics/status_collection.rb', line 17 def find_by_id id @list.find { |status| status.id == id } end |
#find_by_id!(id) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/jirametrics/status_collection.rb', line 21 def find_by_id! id status = @list.find { |status| status.id == id } raise "Can't find any status for id #{id} in #{self}" unless status status end |
#inspect ⇒ Object
89 90 91 |
# File 'lib/jirametrics/status_collection.rb', line 89 def inspect "StatusCollection#{self}" end |
#parse_name_id(name) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/jirametrics/status_collection.rb', line 52 def parse_name_id name # Names could arrive in one of the following formats: "Done:3", "3", "Done" if /^(?<status_name>.*):(?<status_id>\d+)$/ =~ name [status_name, status_id.to_i] elsif name.match?(/^\d+$/) [nil, name.to_i] else [name, nil] end end |
#select(&block) ⇒ Object
79 |
# File 'lib/jirametrics/status_collection.rb', line 79 def select(&block) = @list.select(&block) |
#to_s ⇒ Object
85 86 87 |
# File 'lib/jirametrics/status_collection.rb', line 85 def to_s "[#{@list.sort.join(', ')}]" end |