Class: KalibroClient::Entities::Miscellaneous::Granularity
- Includes:
- Comparable
- Defined in:
- lib/kalibro_client/entities/miscellaneous/granularity.rb
Constant Summary collapse
- GRANULARITIES =
[:METHOD, :CLASS, :PACKAGE, :SOFTWARE, :FUNCTION]
- PARENTS =
{ METHOD: CLASS, CLASS: PACKAGE, PACKAGE: SOFTWARE, SOFTWARE: SOFTWARE, FUNCTION: PACKAGE }
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
FYI: this is a spaceship operator.
-
#initialize(type) ⇒ Granularity
constructor
A new instance of Granularity.
- #is_lower_than?(other_type) ⇒ Boolean
- #parent ⇒ Object
- #to_s ⇒ Object
Methods inherited from Base
Methods included from HashConverters
#convert_to_hash, #date_with_milliseconds, #field_to_hash
Methods included from XMLConverters
#get_xml, #xml_instance_class_name
Constructor Details
#initialize(type) ⇒ Granularity
Returns a new instance of Granularity.
23 24 25 26 27 28 29 30 |
# 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 |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
21 22 23 |
# File 'lib/kalibro_client/entities/miscellaneous/granularity.rb', line 21 def type @type end |
Instance Method Details
#<=>(other) ⇒ Object
FYI: this is a spaceship operator
45 46 47 48 49 50 51 52 53 54 55 |
# 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) ⇒ Boolean
57 58 59 60 61 62 63 64 65 66 |
# 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 ⇒ Object
32 33 34 35 36 37 38 |
# 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 ⇒ Object
40 41 42 |
# File 'lib/kalibro_client/entities/miscellaneous/granularity.rb', line 40 def to_s self.type.to_s end |