Class: TripleCounter
- Inherits:
-
Struct
- Object
- Struct
- TripleCounter
- Defined in:
- lib/distorted/triple_counter.rb
Instance Attribute Summary collapse
-
#major ⇒ Object
Returns the value of attribute major.
-
#micro ⇒ Object
Returns the value of attribute micro.
-
#minor ⇒ Object
Returns the value of attribute minor.
Instance Method Summary collapse
- #<(otra) ⇒ Object
- #<=(otra) ⇒ Object
- #==(otra) ⇒ Object
- #===(otra) ⇒ Object
- #>(otra) ⇒ Object
- #>=(otra) ⇒ Object
- #all_operator(otra, operator) ⇒ Object
-
#initialize(major = 0, minor = 0, micro = 0, *_) ⇒ TripleCounter
constructor
Include a catch-all so we can splat Array-generating functions into TripleCounter.new(), e.g.
- #to_array ⇒ Object
- #to_s ⇒ Object
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
#major ⇒ Object
Returns the value of attribute major
1 2 3 |
# File 'lib/distorted/triple_counter.rb', line 1 def major @major end |
#micro ⇒ Object
Returns the value of attribute micro
1 2 3 |
# File 'lib/distorted/triple_counter.rb', line 1 def micro @micro end |
#minor ⇒ Object
Returns the value of attribute 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_array ⇒ Object
45 46 47 |
# File 'lib/distorted/triple_counter.rb', line 45 def to_array [major, minor, micro] end |
#to_s ⇒ Object
17 18 19 |
# File 'lib/distorted/triple_counter.rb', line 17 def to_s [major, minor, micro].join('.'.freeze) end |