Class: ChangeItem

Inherits:
Object
  • Object
show all
Defined in:
lib/jirametrics/change_item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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
21
22
23
24
25
26
# File 'lib/jirametrics/change_item.rb', line 7

def initialize raw:, author_raw:, time:, artificial: false
  @raw = raw
  @author_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']
  if sprint?
    @value_id = @raw['to'].split(', ').collect(&:to_i)
    @old_value_id = (@raw['from'] || '').split(', ').collect(&:to_i)
  else
    @value_id = @raw['to']&.to_i
    @old_value_id = @raw['from']&.to_i
  end
  @field_id = @raw['fieldId']
  @artificial = artificial
end

Instance Attribute Details

#author_rawObject (readonly)

Returns the value of attribute author_raw.



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

def author_raw
  @author_raw
end

#fieldObject (readonly)

Returns the value of attribute field.



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

def field
  @field
end

#field_idObject (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_valueObject

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_idObject (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

#rawObject (readonly)

Returns the value of attribute raw.



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

def raw
  @raw
end

#timeObject

Returns the value of attribute time.



5
6
7
# File 'lib/jirametrics/change_item.rb', line 5

def time
  @time
end

#valueObject

Returns the value of attribute value.



5
6
7
# File 'lib/jirametrics/change_item.rb', line 5

def value
  @value
end

#value_idObject (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



72
73
74
# File 'lib/jirametrics/change_item.rb', line 72

def == other
  field.eql?(other.field) && value.eql?(other.value) && time_to_s(time).eql?(time_to_s(other.time))
end

#artificial?Boolean

Returns:

  • (Boolean)


36
# File 'lib/jirametrics/change_item.rb', line 36

def artificial? = @artificial

#assignee?Boolean

Returns:

  • (Boolean)


37
# File 'lib/jirametrics/change_item.rb', line 37

def assignee? = (field == 'assignee')

#authorObject



28
29
30
# File 'lib/jirametrics/change_item.rb', line 28

def author
  @author_raw&.[]('displayName') || @author_raw&.[]('name') || 'Unknown author'
end

#author_icon_urlObject



32
33
34
# File 'lib/jirametrics/change_item.rb', line 32

def author_icon_url
  @author_raw&.[]('avatarUrls')&.[]('16x16')
end

#comment?Boolean

Returns:

  • (Boolean)


38
# File 'lib/jirametrics/change_item.rb', line 38

def comment? = (field == 'comment')

#current_status_matches(*status_names_or_ids) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/jirametrics/change_item.rb', line 76

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

Returns:

  • (Boolean)


39
# File 'lib/jirametrics/change_item.rb', line 39

def description? = (field == 'description')

#due_date?Boolean

Returns:

  • (Boolean)


40
# File 'lib/jirametrics/change_item.rb', line 40

def due_date? = (field == 'duedate')

#field_as_human_readableObject



106
107
108
109
110
111
112
113
114
115
# File 'lib/jirametrics/change_item.rb', line 106

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

Returns:

  • (Boolean)


49
# File 'lib/jirametrics/change_item.rb', line 49

def fix_version? = (field == 'Fix Version')

#flagged?Boolean

Returns:

  • (Boolean)


41
# File 'lib/jirametrics/change_item.rb', line 41

def flagged? = (field == 'Flagged')

#inspectObject



70
# File 'lib/jirametrics/change_item.rb', line 70

def inspect = to_s

#issue_type?Boolean

Returns:

  • (Boolean)


42
# File 'lib/jirametrics/change_item.rb', line 42

def issue_type? = field == 'issuetype'

#labels?Boolean

Returns:

  • (Boolean)


43
# File 'lib/jirametrics/change_item.rb', line 43

def labels? = (field == 'labels')

#link?Boolean

Returns:

  • (Boolean)


44
# File 'lib/jirametrics/change_item.rb', line 44

def link? = (field == 'Link')

#old_status_matches(*status_names_or_ids) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/jirametrics/change_item.rb', line 91

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

Returns:

  • (Boolean)


45
# File 'lib/jirametrics/change_item.rb', line 45

def priority? = (field == 'priority')

#resolution?Boolean

Returns:

  • (Boolean)


46
# File 'lib/jirametrics/change_item.rb', line 46

def resolution? = (field == 'resolution')

#sprint?Boolean

Returns:

  • (Boolean)


47
# File 'lib/jirametrics/change_item.rb', line 47

def sprint? = (field == 'Sprint')

#status?Boolean

Returns:

  • (Boolean)


48
# File 'lib/jirametrics/change_item.rb', line 48

def status? = (field == 'status')

#to_sObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/jirametrics/change_item.rb', line 54

def to_s
  message = +''
  message << "ChangeItem(field: #{field.inspect}"
  message << ", value: #{value.inspect}"
  message << ':' << value_id.inspect if value_id
  if old_value
    message << ", old_value: #{old_value.inspect}"
    message << ':' << old_value_id.inspect if old_value_id
  end
  message << ", time: #{time_to_s(@time).inspect}"
  message << ", field_id: #{@field_id.inspect}" if @field_id
  message << ', artificial' if artificial?
  message << ')'
  message
end

#to_timeObject

An alias for time so that logic accepting a Time, Date, or ChangeItem can all respond to :to_time



52
# File 'lib/jirametrics/change_item.rb', line 52

def to_time = @time