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.



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/jirametrics/status.rb', line 52

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
# File 'lib/jirametrics/status.rb', line 38

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

  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



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

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

#==(other) ⇒ Object



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

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)


76
77
78
# File 'lib/jirametrics/status.rb', line 76

def artificial?
  @artificial
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

def eql?(other)
  self == other
end

#global?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/jirametrics/status.rb', line 68

def global?
  !project_scoped?
end

#inspectObject



96
97
98
99
100
101
102
103
104
105
# File 'lib/jirametrics/status.rb', line 96

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)


64
65
66
# File 'lib/jirametrics/status.rb', line 64

def project_scoped?
  !!@project_id
end

#to_sObject



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

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

#value_equality_ignored_variablesObject



107
108
109
# File 'lib/jirametrics/status.rb', line 107

def value_equality_ignored_variables
  [:@raw]
end