Class: ChangeItem
- Inherits:
-
Object
- Object
- ChangeItem
- Defined in:
- lib/jirametrics/change_item.rb
Instance Attribute Summary collapse
-
#author_raw ⇒ Object
readonly
Returns the value of attribute author_raw.
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#field_id ⇒ Object
readonly
Returns the value of attribute field_id.
-
#old_value ⇒ Object
Returns the value of attribute old_value.
-
#old_value_id ⇒ Object
readonly
Returns the value of attribute old_value_id.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#time ⇒ Object
Returns the value of attribute time.
-
#value ⇒ Object
Returns the value of attribute value.
-
#value_id ⇒ Object
readonly
Returns the value of attribute value_id.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #artificial? ⇒ Boolean
- #assignee? ⇒ Boolean
- #author ⇒ Object
- #author_icon_url ⇒ Object
- #comment? ⇒ Boolean
- #current_status_matches(*status_names_or_ids) ⇒ Object
- #description? ⇒ Boolean
- #due_date? ⇒ Boolean
- #field_as_human_readable ⇒ Object
- #fix_version? ⇒ Boolean
- #flagged? ⇒ Boolean
-
#initialize(raw:, author_raw:, time:, artificial: false) ⇒ ChangeItem
constructor
A new instance of ChangeItem.
- #inspect ⇒ Object
- #issue_type? ⇒ Boolean
- #labels? ⇒ Boolean
- #link? ⇒ Boolean
- #old_status_matches(*status_names_or_ids) ⇒ Object
-
#parse_multiple_integer_values(raw_value) ⇒ Object
Parses a comma-separated string of integers into a list.
-
#parse_value_ids ⇒ Object
Sprints carry a comma-separated list of ids in 'to'/'from', so those become arrays.
- #priority? ⇒ Boolean
- #resolution? ⇒ Boolean
- #sprint? ⇒ Boolean
- #status? ⇒ Boolean
- #to_s ⇒ Object
-
#to_time ⇒ Object
An alias for time so that logic accepting a Time, Date, or ChangeItem can all respond to :to_time.
Constructor Details
#initialize(raw:, author_raw:, time:, artificial: false) ⇒ ChangeItem
Returns a new instance of ChangeItem.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/jirametrics/change_item.rb', line 7 def initialize raw:, author_raw:, time:, artificial: false @raw = raw @author_raw = @time = time raise 'ChangeItem.new() time cannot be nil' if time.nil? raise "Time must be an object of type Time in the correct timezone: #{@time.inspect}" unless @time.is_a? Time @field = @raw['field'] @value = @raw['toString'] @old_value = @raw['fromString'] @value_id, @old_value_id = parse_value_ids @field_id = @raw['fieldId'] @artificial = artificial end |
Instance Attribute Details
#author_raw ⇒ Object (readonly)
Returns the value of attribute author_raw.
4 5 6 |
# File 'lib/jirametrics/change_item.rb', line 4 def @author_raw end |
#field ⇒ Object (readonly)
Returns the value of attribute field.
4 5 6 |
# File 'lib/jirametrics/change_item.rb', line 4 def field @field end |
#field_id ⇒ Object (readonly)
Returns the value of attribute field_id.
4 5 6 |
# File 'lib/jirametrics/change_item.rb', line 4 def field_id @field_id end |
#old_value ⇒ Object
Returns the value of attribute old_value.
5 6 7 |
# File 'lib/jirametrics/change_item.rb', line 5 def old_value @old_value end |
#old_value_id ⇒ Object (readonly)
Returns the value of attribute old_value_id.
4 5 6 |
# File 'lib/jirametrics/change_item.rb', line 4 def old_value_id @old_value_id end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
4 5 6 |
# File 'lib/jirametrics/change_item.rb', line 4 def raw @raw end |
#time ⇒ Object
Returns the value of attribute time.
5 6 7 |
# File 'lib/jirametrics/change_item.rb', line 5 def time @time end |
#value ⇒ Object
Returns the value of attribute value.
5 6 7 |
# File 'lib/jirametrics/change_item.rb', line 5 def value @value end |
#value_id ⇒ Object (readonly)
Returns the value of attribute value_id.
4 5 6 |
# File 'lib/jirametrics/change_item.rb', line 4 def value_id @value_id end |
Instance Method Details
#==(other) ⇒ Object
84 85 86 |
# File 'lib/jirametrics/change_item.rb', line 84 def == other field.eql?(other.field) && value.eql?(other.value) && time_to_s(time).eql?(time_to_s(other.time)) end |
#artificial? ⇒ Boolean
48 |
# File 'lib/jirametrics/change_item.rb', line 48 def artificial? = @artificial |
#assignee? ⇒ Boolean
49 |
# File 'lib/jirametrics/change_item.rb', line 49 def assignee? = (field == 'assignee') |
#author ⇒ Object
40 41 42 |
# File 'lib/jirametrics/change_item.rb', line 40 def @author_raw&.[]('displayName') || @author_raw&.[]('name') || 'Unknown author' end |
#author_icon_url ⇒ Object
44 45 46 |
# File 'lib/jirametrics/change_item.rb', line 44 def @author_raw&.[]('avatarUrls')&.[]('16x16') end |
#comment? ⇒ Boolean
50 |
# File 'lib/jirametrics/change_item.rb', line 50 def comment? = (field == 'comment') |
#current_status_matches(*status_names_or_ids) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/jirametrics/change_item.rb', line 88 def current_status_matches *status_names_or_ids return false unless status? status_names_or_ids.any? do |name_or_id| case name_or_id when Status name_or_id.id == @value_id when String name_or_id == @value else name_or_id == @value_id end end end |
#description? ⇒ Boolean
51 |
# File 'lib/jirametrics/change_item.rb', line 51 def description? = (field == 'description') |
#due_date? ⇒ Boolean
52 |
# File 'lib/jirametrics/change_item.rb', line 52 def due_date? = (field == 'duedate') |
#field_as_human_readable ⇒ Object
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/jirametrics/change_item.rb', line 118 def field_as_human_readable case @field when 'duedate' then 'Due date' when 'timeestimate' then 'Time estimate' when 'timeoriginalestimate' then 'Time original estimate' when 'issuetype' then 'Issue type' when 'IssueParentAssociation' then 'Issue parent association' else @field.capitalize end end |
#fix_version? ⇒ Boolean
61 |
# File 'lib/jirametrics/change_item.rb', line 61 def fix_version? = (field == 'Fix Version') |
#flagged? ⇒ Boolean
53 |
# File 'lib/jirametrics/change_item.rb', line 53 def flagged? = (field == 'Flagged') |
#inspect ⇒ Object
82 |
# File 'lib/jirametrics/change_item.rb', line 82 def inspect = to_s |
#issue_type? ⇒ Boolean
54 |
# File 'lib/jirametrics/change_item.rb', line 54 def issue_type? = field == 'issuetype' |
#labels? ⇒ Boolean
55 |
# File 'lib/jirametrics/change_item.rb', line 55 def labels? = (field == 'labels') |
#link? ⇒ Boolean
56 |
# File 'lib/jirametrics/change_item.rb', line 56 def link? = (field == 'Link') |
#old_status_matches(*status_names_or_ids) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/jirametrics/change_item.rb', line 103 def old_status_matches *status_names_or_ids return false unless status? status_names_or_ids.any? do |name_or_id| case name_or_id when Status name_or_id.id == @old_value_id when String name_or_id == @old_value else name_or_id == @old_value_id end end end |
#parse_multiple_integer_values(raw_value) ⇒ Object
Parses a comma-separated string of integers into a list. Sprint is the only field we currently parse this way, but the operation is generic - other fields may turn out to carry multiple ids too. to_s turns a nil (no value) into an empty list.
36 37 38 |
# File 'lib/jirametrics/change_item.rb', line 36 def parse_multiple_integer_values raw_value raw_value.to_s.split(', ').collect(&:to_i) end |
#parse_value_ids ⇒ Object
Sprints carry a comma-separated list of ids in 'to'/'from', so those become arrays. Every other field is treated as a single id: to_i grabs the leading number, or 0 for text/bracketed values like Watchers or Markets (whose value_id is never used as a real id anyway).
25 26 27 28 29 30 31 |
# File 'lib/jirametrics/change_item.rb', line 25 def parse_value_ids to = @raw['to'] from = @raw['from'] return [to&.to_i, from&.to_i] unless sprint? [parse_multiple_integer_values(to), parse_multiple_integer_values(from)] end |
#priority? ⇒ Boolean
57 |
# File 'lib/jirametrics/change_item.rb', line 57 def priority? = (field == 'priority') |
#resolution? ⇒ Boolean
58 |
# File 'lib/jirametrics/change_item.rb', line 58 def resolution? = (field == 'resolution') |
#sprint? ⇒ Boolean
59 |
# File 'lib/jirametrics/change_item.rb', line 59 def sprint? = (field == 'Sprint') |
#status? ⇒ Boolean
60 |
# File 'lib/jirametrics/change_item.rb', line 60 def status? = (field == 'status') |
#to_s ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/jirametrics/change_item.rb', line 66 def to_s = +'' << "ChangeItem(field: #{field.inspect}" << ", value: #{value.inspect}" << ':' << value_id.inspect if value_id if old_value << ", old_value: #{old_value.inspect}" << ':' << old_value_id.inspect if old_value_id end << ", time: #{time_to_s(@time).inspect}" << ", field_id: #{@field_id.inspect}" if @field_id << ', artificial' if artificial? << ')' end |
#to_time ⇒ Object
An alias for time so that logic accepting a Time, Date, or ChangeItem can all respond to :to_time
64 |
# File 'lib/jirametrics/change_item.rb', line 64 def to_time = @time |