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

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

Defined Under Namespace

Classes: NameConventionError

Constant Summary collapse

SPRINT_PREFIX_SEPARATOR =
"_"
NUMBERING_SEPARATOR =
"."
SPRINT_NAME_REGEX =
/
(.+)                                         # prefix
#{Regexp.escape(SPRINT_PREFIX_SEPARATOR)}
(\d\d)                                       # year
#{Regexp.escape(NUMBERING_SEPARATOR)}
(\d)                                         # quarter
#{Regexp.escape(NUMBERING_SEPARATOR)}
(\d+)                                        # index in quarter
$/x
FIELDS =
%i[prefix year quarter index_in_quarter].freeze
YEAR_AS_TWO_DIGIT_RANGE =
-2..-1

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prefix, year, quarter, index_in_quarter) ⇒ Name

Returns a new instance of Name.



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

def initialize(prefix, year, quarter, index_in_quarter)
  @prefix = prefix
  @year = year
  @quarter = quarter
  @index_in_quarter = index_in_quarter
end

Class Method Details

.build(prefix, year, quarter, index) ⇒ Object



40
41
42
43
# File 'lib/jira/auto/tool/sprint/name.rb', line 40

def self.build(prefix, year, quarter, index)
  new(prefix, year, quarter, index)
    .to_s
end

.new_with(prefix, suffix) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/jira/auto/tool/sprint/name.rb', line 45

def self.new_with(prefix, suffix)
  name = [prefix, suffix].join(SPRINT_PREFIX_SEPARATOR)

  respects_naming_convention?(name) ||
    raise(NameConventionError,
          "suffix not following convention '#{suffix}': " \
          "resulting sprint name '#{name}' " \
          "not matching #{SPRINT_NAME_REGEX}!")

  parse(name)
end

.parse(name_string) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/jira/auto/tool/sprint/name.rb', line 30

def self.parse(name_string)
  name_string =~ SPRINT_NAME_REGEX ||
    raise(NameConventionError,
          "'#{name_string}': " \
          "sprint name not matching #{SPRINT_NAME_REGEX}!")

  new(::Regexp.last_match(1), ::Regexp.last_match(2).to_i, ::Regexp.last_match(3).to_i,
      ::Regexp.last_match(4).to_i)
end

.respects_naming_convention?(name_string) ⇒ Boolean

Returns:

  • (Boolean)


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

def self.respects_naming_convention?(name_string)
  SPRINT_NAME_REGEX.match? name_string
end

Instance Method Details

#<=>(other) ⇒ Object



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

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

#next_in_planning_intervalObject



86
87
88
# File 'lib/jira/auto/tool/sprint/name.rb', line 86

def next_in_planning_interval
  self.class.new(prefix, year, quarter, index_in_quarter + 1)
end

#planning_intervalObject



82
83
84
# File 'lib/jira/auto/tool/sprint/name.rb', line 82

def planning_interval
  [year, quarter]
end

#to_sObject



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/jira/auto/tool/sprint/name.rb', line 70

def to_s
  [
    prefix,
    SPRINT_PREFIX_SEPARATOR,
    year.to_s[YEAR_AS_TWO_DIGIT_RANGE],
    NUMBERING_SEPARATOR,
    quarter,
    NUMBERING_SEPARATOR,
    index_in_quarter
  ].join
end