Class: Status

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

Defined Under Namespace

Classes: Category

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, id:, category_name:, category_id:, category_key:, project_id: nil, artificial: true) ⇒ Status

Returns a new instance of Status.



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/jirametrics/status.rb', line 58

def initialize name:, id:, category_name:, category_id:, category_key:, project_id: nil, artificial: true
  # These checks are needed because nils used to be possible and now they aren't.
  raise 'id cannot be nil' if id.nil?
  raise 'category_id cannot be nil' if category_id.nil?

  @name = name
  @id = id
  @category = Category.new id: category_id, name: category_name, key: category_key
  @project_id = project_id
  @artificial = artificial
end

Instance Attribute Details

#categoryObject (readonly)

Returns the value of attribute category.



6
7
8
# File 'lib/jirametrics/status.rb', line 6

def category
  @category
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/jirametrics/status.rb', line 6

def id
  @id
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/jirametrics/status.rb', line 7

def name
  @name
end

#project_idObject (readonly)

Returns the value of attribute project_id.



6
7
8
# File 'lib/jirametrics/status.rb', line 6

def project_id
  @project_id
end

Class Method Details

.from_raw(raw) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/jirametrics/status.rb', line 38

def self.from_raw raw
  category_config = raw['statusCategory']

  legal_keys = %w[new indeterminate done]
  unless legal_keys.include? category_config['key']
    puts "Category key #{category_config['key'].inspect} should be one of #{legal_keys.inspect}. Found:\n" \
      "#{category_config}"
  end

  Status.new(
    name: raw['name'],
    id: raw['id'].to_i,
    category_name: category_config['name'],
    category_id: category_config['id'].to_i,
    category_key: category_config['key'],
    project_id: raw['scope']&.[]('project')&.[]('id'),
    artificial: false
  )
end

Instance Method Details

#<=>(other) ⇒ Object



96
97
98
99
100
# File 'lib/jirametrics/status.rb', line 96

def <=> other
  result = @name.casecmp(other.name)
  result = @id <=> other.id if result.zero?
  result
end

#==(other) ⇒ Object



86
87
88
89
90
# File 'lib/jirametrics/status.rb', line 86

def == other
  return false unless other.is_a? Status

  @id == other.id && @name == other.name && @category.id == other.category.id && @category.name == other.category.name
end

#artificial?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/jirametrics/status.rb', line 82

def artificial?
  @artificial
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/jirametrics/status.rb', line 92

def eql?(other)
  self == other
end

#global?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/jirametrics/status.rb', line 74

def global?
  !project_scoped?
end

#inspectObject



102
103
104
105
106
107
108
109
110
111
# File 'lib/jirametrics/status.rb', line 102

def inspect
  result = []
  result << "Status(name: #{@name.inspect}"
  result << "id: #{@id.inspect}"
  result << "project_id: #{@project_id}" if @project_id
  category = self.category
  result << "category: {name:#{category.name.inspect}, id: #{category.id.inspect}, key: #{category.key.inspect}}"
  result << 'artificial' if artificial?
  result.join(', ') << ')'
end

#project_scoped?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/jirametrics/status.rb', line 70

def project_scoped?
  !!@project_id
end

#to_sObject



78
79
80
# File 'lib/jirametrics/status.rb', line 78

def to_s
  "#{name.inspect}:#{id.inspect}"
end

#value_equality_ignored_variablesObject



113
114
115
# File 'lib/jirametrics/status.rb', line 113

def value_equality_ignored_variables
  [:@raw]
end