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.



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/jirametrics/status.rb', line 55

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

def self.from_raw raw
  raise "raw cannot be nil" if raw.nil?

  category_config = raw['statusCategory']
  raise "statusCategory can't be nil in #{category_config.inspect}" if category_config.nil?

  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



93
94
95
96
97
# File 'lib/jirametrics/status.rb', line 93

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

#==(other) ⇒ Object



83
84
85
86
87
# File 'lib/jirametrics/status.rb', line 83

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)


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

def artificial?
  @artificial
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/jirametrics/status.rb', line 89

def eql?(other)
  self == other
end

#global?Boolean

Returns:

  • (Boolean)


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

def global?
  !project_scoped?
end

#inspectObject



99
100
101
102
103
104
105
106
107
108
# File 'lib/jirametrics/status.rb', line 99

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)


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

def project_scoped?
  !!@project_id
end

#to_sObject



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

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

#value_equality_ignored_variablesObject



110
111
112
# File 'lib/jirametrics/status.rb', line 110

def value_equality_ignored_variables
  [:@raw]
end