class KalibroClient::Entities::Miscellaneous::Granularity

Constants

GRANULARITIES
PARENTS

Attributes

type[R]

Public Class Methods

new(type) click to toggle source
# File lib/kalibro_client/entities/miscellaneous/granularity.rb, line 23
def initialize(type)
  type = type.to_sym
  if GRANULARITIES.include?(type)
    @type = type
  else
    raise TypeError.new("Not supported granularity type #{type}")
  end
end

Public Instance Methods

<=>(other) click to toggle source

FYI: this is a spaceship operator

# File lib/kalibro_client/entities/miscellaneous/granularity.rb, line 45
def <=>(other)
  return nil if [[:FUNCTION, :METHOD], [:METHOD, :FUNCTION], [:FUNCTION, :CLASS], [:CLASS, :FUNCTION]].include?([self.type, other.type])

  if self.type == other.type
    return 0
  elsif self.is_lower_than?(other.type)
    return -1
  else
    return 1
  end
end
is_lower_than?(other_type) click to toggle source
# File lib/kalibro_client/entities/miscellaneous/granularity.rb, line 57
def is_lower_than?(other_type)
  current_type = self.type

  while current_type != PARENTS[current_type]
    return true if PARENTS[current_type] == other_type
    current_type = PARENTS[current_type]
  end

  return false
end
parent() click to toggle source
# File lib/kalibro_client/entities/miscellaneous/granularity.rb, line 32
def parent
  parent_type = PARENTS[self.type]
  raise ArgumentError.new("Not supported granularity type #{type}") if parent_type.nil?

  return self if self.type == parent_type
  Granularity.new(parent_type)
end
to_s() click to toggle source
# File lib/kalibro_client/entities/miscellaneous/granularity.rb, line 40
def to_s
  self.type.to_s
end