Class: Jira::Auto::Tool::Sprint

Inherits:
SimpleDelegator
  • Object
show all
Includes:
Comparable
Defined in:
lib/jira/auto/tool/sprint.rb,
lib/jira/auto/tool/sprint/name.rb,
lib/jira/auto/tool/sprint/prefix.rb

Defined Under Namespace

Classes: Name, Prefix

Constant Summary collapse

UNDEFINED_DATE =
Time.new(1970, 1, 1, 0, 0, 0, "UTC")

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tool, jira_sprint) ⇒ Sprint

Returns a new instance of Sprint.



28
29
30
31
32
# File 'lib/jira/auto/tool/sprint.rb', line 28

def initialize(tool, jira_sprint)
  super(jira_sprint)
  @tool = tool
  @jira_sprint = jira_sprint
end

Instance Attribute Details

#jira_sprintObject (readonly)

Returns the value of attribute jira_sprint.



26
27
28
# File 'lib/jira/auto/tool/sprint.rb', line 26

def jira_sprint
  @jira_sprint
end

#toolObject (readonly)

Returns the value of attribute tool.



26
27
28
# File 'lib/jira/auto/tool/sprint.rb', line 26

def tool
  @tool
end

Class Method Details

.date_for_save(date) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/jira/auto/tool/sprint.rb', line 14

def self.date_for_save(date)
  case date
  when Time, Date, DateTime
    date
  when String
    Time.parse(date)
  else
    raise ArgumentError, "#{date.inspect} (#{date.class}), date must be a Time, Date, DateTime or a String"
  end
    .utc.iso8601
end

.to_table_row_field_namesObject



140
141
142
# File 'lib/jira/auto/tool/sprint.rb', line 140

def self.to_table_row_field_names
  i[id name length_in_days start_date end_date]
end

.to_table_row_header(without_board_information: false) ⇒ Object



144
145
146
147
148
149
150
# File 'lib/jira/auto/tool/sprint.rb', line 144

def self.to_table_row_header(without_board_information: false)
  header = to_table_row_field_names.collect { |field| field.to_s.titleize }

  header.concat(Board.to_table_row_header.collect { |field| "Board #{field}" }) unless without_board_information

  header
end

Instance Method Details

#<=>(other) ⇒ Object



132
133
134
# File 'lib/jira/auto/tool/sprint.rb', line 132

def <=>(other)
  comparison_values(self) <=> comparison_values(other)
end

#boardObject



116
117
118
# File 'lib/jira/auto/tool/sprint.rb', line 116

def board
  @board ||= Board.find_by_id(tool, origin_board_id)
end

#closed?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/jira/auto/tool/sprint.rb', line 104

def closed?
  state == SprintStateController::SprintState::CLOSED
end

#end_dateObject



58
59
60
# File 'lib/jira/auto/tool/sprint.rb', line 58

def end_date
  get_optional_date :endDate
end

#end_date=(date) ⇒ Object



62
63
64
# File 'lib/jira/auto/tool/sprint.rb', line 62

def end_date=(date)
  jira_sprint.attrs["endDate"] = self.class.date_for_save(date)
end

#end_date?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/jira/auto/tool/sprint.rb', line 66

def end_date?
  end_date != UNDEFINED_DATE
end

#get_optional_date(jira_field_id) ⇒ Object



72
73
74
75
76
# File 'lib/jira/auto/tool/sprint.rb', line 72

def get_optional_date(jira_field_id)
  return UNDEFINED_DATE unless jira_sprint.respond_to?(jira_field_id)

  parse_date(jira_sprint.send(jira_field_id))
end

#idObject



34
35
36
# File 'lib/jira/auto/tool/sprint.rb', line 34

def id
  @jira_sprint.id
end

#index_in_quarterObject



112
113
114
# File 'lib/jira/auto/tool/sprint.rb', line 112

def index_in_quarter
  parsed_name.index_in_quarter
end

#jira_clientObject



120
121
122
# File 'lib/jira/auto/tool/sprint.rb', line 120

def jira_client
  @jira_sprint.client
end

#length_in_daysObject



42
43
44
# File 'lib/jira/auto/tool/sprint.rb', line 42

def length_in_days
  (end_date - start_date) / 1.day
end

#missing_dates?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/jira/auto/tool/sprint.rb', line 78

def missing_dates?
  start_date == UNDEFINED_DATE || end_date == UNDEFINED_DATE
end

#nameObject



38
39
40
# File 'lib/jira/auto/tool/sprint.rb', line 38

def name
  @jira_sprint.name
end

#name_prefixObject



124
125
126
# File 'lib/jira/auto/tool/sprint.rb', line 124

def name_prefix
  parsed_name.prefix
end

#origin_board_idObject



108
109
110
# File 'lib/jira/auto/tool/sprint.rb', line 108

def origin_board_id
  @jira_sprint.originBoardId
end

#parsed_nameObject



128
129
130
# File 'lib/jira/auto/tool/sprint.rb', line 128

def parsed_name
  Name.parse(name)
end

#remove_attributes_that_causes_errors_on_saveObject



96
97
98
# File 'lib/jira/auto/tool/sprint.rb', line 96

def remove_attributes_that_causes_errors_on_save
  jira_sprint.attrs.delete("rapidview_id")
end

#rename_to(new_name) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/jira/auto/tool/sprint.rb', line 82

def rename_to(new_name)
  return if new_name == name || closed?

  jira_sprint.attrs["name"] = new_name

  save
end

#saveObject



90
91
92
93
94
# File 'lib/jira/auto/tool/sprint.rb', line 90

def save
  remove_attributes_that_causes_errors_on_save

  jira_sprint.save!
end

#start_dateObject



46
47
48
# File 'lib/jira/auto/tool/sprint.rb', line 46

def start_date
  get_optional_date :startDate
end

#start_date=(date) ⇒ Object



50
51
52
# File 'lib/jira/auto/tool/sprint.rb', line 50

def start_date=(date)
  jira_sprint.attrs["startDate"] = self.class.date_for_save(date)
end

#start_date?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/jira/auto/tool/sprint.rb', line 54

def start_date?
  start_date != UNDEFINED_DATE
end

#stateObject



100
101
102
# File 'lib/jira/auto/tool/sprint.rb', line 100

def state
  @jira_sprint.state
end

#to_sObject



136
137
138
# File 'lib/jira/auto/tool/sprint.rb', line 136

def to_s
  "name = #{name}, start_date = #{start_date}, end_date = #{end_date}, length_in_days = #{length_in_days}"
end

#to_table_row(without_board_information: false) ⇒ Object



152
153
154
155
156
157
158
159
160
# File 'lib/jira/auto/tool/sprint.rb', line 152

def to_table_row(without_board_information: false)
  row = self.class.to_table_row_field_names.collect { |field| send(field) }

  row.concat(board.to_table_row) unless without_board_information

  row
rescue StandardError => e
  raise e.class, "#{e.class}: sprint #{name.inspect}: #{e.message}:\n#{inspect}"
end