Class: StatusCollection
- Inherits:
-
Object
- Object
- StatusCollection
- Defined in:
- lib/jirametrics/status_collection.rb
Instance Attribute Summary collapse
-
#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:) ⇒ 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 |
# File 'lib/jirametrics/status_collection.rb', line 9 def initialize @list = [] @historical_status_mappings = {} # 'name:id' => category end |
Instance Attribute Details
#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
78 |
# File 'lib/jirametrics/status_collection.rb', line 78 def <<(arg) = @list << arg |
#clear ⇒ Object
80 |
# File 'lib/jirametrics/status_collection.rb', line 80 def clear = @list.clear |
#collect(&block) ⇒ Object
74 |
# File 'lib/jirametrics/status_collection.rb', line 74 def collect(&block) = @list.collect(&block) |
#delete(object) ⇒ Object
81 |
# File 'lib/jirametrics/status_collection.rb', line 81 def delete(object) = @list.delete(object) |
#each(&block) ⇒ Object
76 |
# File 'lib/jirametrics/status_collection.rb', line 76 def each(&block) = @list.each(&block) |
#empty? ⇒ Boolean
79 |
# File 'lib/jirametrics/status_collection.rb', line 79 def empty? = @list.empty? |
#fabricate_status_for(id:, name:) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/jirametrics/status_collection.rb', line 91 def fabricate_status_for id:, name: category = @historical_status_mappings["#{name.inspect}:#{id.inspect}"] category = in_progress_category 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 status end |
#find(&block) ⇒ Object
75 |
# File 'lib/jirametrics/status_collection.rb', line 75 def find(&block) = @list.find(&block) |
#find_all_by_name(identifier) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/jirametrics/status_collection.rb', line 26 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
43 44 45 46 47 48 |
# File 'lib/jirametrics/status_collection.rb', line 43 def find_all_categories @list .collect(&:category) .uniq .sort_by(&:id) end |
#find_all_categories_by_name(identifier) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/jirametrics/status_collection.rb', line 61 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.
15 16 17 |
# File 'lib/jirametrics/status_collection.rb', line 15 def find_by_id id @list.find { |status| status.id == id } end |
#find_by_id!(id) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/jirametrics/status_collection.rb', line 19 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
87 88 89 |
# File 'lib/jirametrics/status_collection.rb', line 87 def inspect "StatusCollection#{self}" end |
#parse_name_id(name) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/jirametrics/status_collection.rb', line 50 def parse_name_id name # Names could arrive in one of the following formats: "Done:3", "3", "Done" if name =~ /^(.*):(\d+)$/ [$1, $2.to_i] elsif name.match?(/^\d+$/) [nil, name.to_i] else [name, nil] end end |
#select(&block) ⇒ Object
77 |
# File 'lib/jirametrics/status_collection.rb', line 77 def select(&block) = @list.select(&block) |
#to_s ⇒ Object
83 84 85 |
# File 'lib/jirametrics/status_collection.rb', line 83 def to_s "[#{@list.sort.join(', ')}]" end |