Class: TripleCounter

Inherits:
Struct
  • Object
show all
Defined in:
lib/distorted/modular_technology/triple_counter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(major = 0, minor = 0, micro = 0) ⇒ TripleCounter

Returns a new instance of TripleCounter.



4
5
6
7
8
# File 'lib/distorted/modular_technology/triple_counter.rb', line 4

def initialize(major = 0, minor = 0, micro = 0)
  @major = major
  @minor = minor
  @micro = micro
end

Instance Attribute Details

#majorObject

Returns the value of attribute major

Returns:

  • (Object)

    the current value of major



1
2
3
# File 'lib/distorted/modular_technology/triple_counter.rb', line 1

def major
  @major
end

#microObject

Returns the value of attribute micro

Returns:

  • (Object)

    the current value of micro



1
2
3
# File 'lib/distorted/modular_technology/triple_counter.rb', line 1

def micro
  @micro
end

#minorObject

Returns the value of attribute minor

Returns:

  • (Object)

    the current value of minor



1
2
3
# File 'lib/distorted/modular_technology/triple_counter.rb', line 1

def minor
  @minor
end

Instance Method Details

#<(otra) ⇒ Object



34
35
36
# File 'lib/distorted/modular_technology/triple_counter.rb', line 34

def <(otra)
  all_operator(otra, :<)
end

#<=(otra) ⇒ Object



26
27
28
# File 'lib/distorted/modular_technology/triple_counter.rb', line 26

def <=(otra)
  all_operator(otra, :<=)
end

#==(otra) ⇒ Object



14
15
16
# File 'lib/distorted/modular_technology/triple_counter.rb', line 14

def ==(otra)
  major == otra.major && minor == otra.minor
end

#===(otra) ⇒ Object



18
19
20
# File 'lib/distorted/modular_technology/triple_counter.rb', line 18

def ===(otra)
  all_operator(otra, :==)
end

#>(otra) ⇒ Object



30
31
32
# File 'lib/distorted/modular_technology/triple_counter.rb', line 30

def >(otra)
  all_operator(otra, :>)
end

#>=(otra) ⇒ Object



22
23
24
# File 'lib/distorted/modular_technology/triple_counter.rb', line 22

def >=(otra)
  all_operator(otra, :>=)
end

#all_operator(otra, operator) ⇒ Object



42
43
44
# File 'lib/distorted/modular_technology/triple_counter.rb', line 42

def all_operator(otra, operator)
  to_array.zip(otra.to_array).all?{|us, otra| us.send(operator, otra)}
end

#to_arrayObject



38
39
40
# File 'lib/distorted/modular_technology/triple_counter.rb', line 38

def to_array
  [major, minor, micro]
end

#to_sObject



10
11
12
# File 'lib/distorted/modular_technology/triple_counter.rb', line 10

def to_s
  [major, minor, micro].join('.'.freeze)
end