Class: ChangeItem
- Inherits:
-
Object
- Object
- ChangeItem
- Defined in:
- lib/jirametrics/change_item.rb
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#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
readonly
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
- #author ⇒ Object
- #author_icon_url ⇒ Object
- #comment? ⇒ Boolean
- #current_status_matches(*status_names_or_ids) ⇒ Object
- #flagged? ⇒ Boolean
-
#initialize(raw:, author_raw:, time:, artificial: false) ⇒ ChangeItem
constructor
A new instance of ChangeItem.
- #inspect ⇒ Object
- #labels? ⇒ Boolean
- #link? ⇒ Boolean
- #old_status_matches(*status_names_or_ids) ⇒ Object
- #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'] @value_id = @raw['to'].to_i @old_value = @raw['fromString'] @old_value_id = @raw['from']&.to_i @artificial = artificial end |
Instance Attribute Details
#field ⇒ Object (readonly)
Returns the value of attribute field.
4 5 6 |
# File 'lib/jirametrics/change_item.rb', line 4 def field @field 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 (readonly)
Returns the value of attribute time.
4 5 6 |
# File 'lib/jirametrics/change_item.rb', line 4 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
68 69 70 |
# File 'lib/jirametrics/change_item.rb', line 68 def == other field.eql?(other.field) && value.eql?(other.value) && time_to_s(time).eql?(time_to_s(other.time)) end |
#artificial? ⇒ Boolean
38 |
# File 'lib/jirametrics/change_item.rb', line 38 def artificial? = @artificial |
#author ⇒ Object
22 23 24 |
# File 'lib/jirametrics/change_item.rb', line 22 def @author_raw&.[]('displayName') || @author_raw&.[]('name') || 'Unknown author' end |
#author_icon_url ⇒ Object
26 27 28 |
# File 'lib/jirametrics/change_item.rb', line 26 def @author_raw&.[]('avatarUrls')&.[]('16x16') end |
#comment? ⇒ Boolean
46 |
# File 'lib/jirametrics/change_item.rb', line 46 def comment? = (field == 'comment') |
#current_status_matches(*status_names_or_ids) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/jirametrics/change_item.rb', line 72 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 |
#flagged? ⇒ Boolean
32 |
# File 'lib/jirametrics/change_item.rb', line 32 def flagged? = (field == 'Flagged') |
#inspect ⇒ Object
66 |
# File 'lib/jirametrics/change_item.rb', line 66 def inspect = to_s |
#labels? ⇒ Boolean
44 |
# File 'lib/jirametrics/change_item.rb', line 44 def labels? = (field == 'labels') |
#link? ⇒ Boolean
42 |
# File 'lib/jirametrics/change_item.rb', line 42 def link? = (field == 'Link') |
#old_status_matches(*status_names_or_ids) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/jirametrics/change_item.rb', line 87 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 |
#priority? ⇒ Boolean
34 |
# File 'lib/jirametrics/change_item.rb', line 34 def priority? = (field == 'priority') |
#resolution? ⇒ Boolean
36 |
# File 'lib/jirametrics/change_item.rb', line 36 def resolution? = (field == 'resolution') |
#sprint? ⇒ Boolean
40 |
# File 'lib/jirametrics/change_item.rb', line 40 def sprint? = (field == 'Sprint') |
#status? ⇒ Boolean
30 |
# File 'lib/jirametrics/change_item.rb', line 30 def status? = (field == 'status') |
#to_s ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/jirametrics/change_item.rb', line 51 def to_s = +'' << "ChangeItem(field: #{field.inspect}" << ", value: #{value.inspect}" << ':' << value_id.inspect if status? if old_value << ", old_value: #{old_value.inspect}" << ':' << old_value_id.inspect if status? end << ", time: #{time_to_s(@time).inspect}" << ', 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
49 |
# File 'lib/jirametrics/change_item.rb', line 49 def to_time = @time |