Class: TripleCounter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Include a catch-all so we can splat Array-generating functions into TripleCounter.new(), e.g. Ruby/GStreamer’s library version:

irb> require 'gst'
=> true
irb> Gst.version
=> [1, 19, 0, 1]


10
11
12
13
14
15
# File 'lib/distorted/triple_counter.rb', line 10

def initialize(major = 0, minor = 0, micro = 0, *_)
  @major = major
  @minor = minor
  @micro = micro
  super(major, minor, micro)  # Intentionally not passing our splat to `super`
end

Instance Attribute Details

#majorObject

Returns the value of attribute major

Returns:

  • (Object)

    the current value of major



1
2
3
# File 'lib/distorted/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/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/triple_counter.rb', line 1

def minor
  @minor
end

Instance Method Details

#<(otra) ⇒ Object



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

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

#<=(otra) ⇒ Object



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

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

#==(otra) ⇒ Object



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

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

#===(otra) ⇒ Object



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

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

#>(otra) ⇒ Object



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

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

#>=(otra) ⇒ Object



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

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

#all_operator(otra, operator) ⇒ Object



49
50
51
# File 'lib/distorted/triple_counter.rb', line 49

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

#to_arrayObject



45
46
47
# File 'lib/distorted/triple_counter.rb', line 45

def to_array
  [major, minor, micro]
end

#to_sObject



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

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