Class: Fractify::Operator
- Inherits:
-
Object
- Object
- Fractify::Operator
- Defined in:
- lib/fractify/operator.rb
Instance Attribute Summary collapse
-
#executed ⇒ Object
Returns the value of attribute executed.
-
#operator_character ⇒ Object
Returns the value of attribute operator_character.
-
#rank ⇒ Object
Returns the value of attribute rank.
-
#to_left ⇒ Object
Returns the value of attribute to_left.
-
#to_right ⇒ Object
Returns the value of attribute to_right.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #decrease_rank!(number = 1) ⇒ Object
- #executed! ⇒ Object
- #executed? ⇒ Boolean
- #increase_rank!(number = 1) ⇒ Object
-
#initialize(operator_character, rank, to_left = nil, to_right = nil) ⇒ Operator
constructor
A new instance of Operator.
- #not_executed? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(operator_character, rank, to_left = nil, to_right = nil) ⇒ Operator
Returns a new instance of Operator.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/fractify/operator.rb', line 8 def initialize(operator_character, rank, to_left = nil, to_right = nil) if to_left && !to_left.is_a?(Fractify::Fraction) || to_right && !to_right.is_a?(Fractify::Fraction) raise IncorrectArgumentsError end self.operator_character = operator_character self.rank = rank self.to_left = to_left self.to_right = to_right self.executed = false end |
Instance Attribute Details
#executed ⇒ Object
Returns the value of attribute executed.
6 7 8 |
# File 'lib/fractify/operator.rb', line 6 def executed @executed end |
#operator_character ⇒ Object
Returns the value of attribute operator_character.
6 7 8 |
# File 'lib/fractify/operator.rb', line 6 def operator_character @operator_character end |
#rank ⇒ Object
Returns the value of attribute rank.
6 7 8 |
# File 'lib/fractify/operator.rb', line 6 def rank @rank end |
#to_left ⇒ Object
Returns the value of attribute to_left.
6 7 8 |
# File 'lib/fractify/operator.rb', line 6 def to_left @to_left end |
#to_right ⇒ Object
Returns the value of attribute to_right.
6 7 8 |
# File 'lib/fractify/operator.rb', line 6 def to_right @to_right end |
Instance Method Details
#<=>(other) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/fractify/operator.rb', line 20 def <=>(other) raise IncorrectArgumentsError unless other.is_a? Fractify::Operator return 0 if rank == other.rank return 1 if rank > other.rank -1 end |
#decrease_rank!(number = 1) ⇒ Object
32 33 34 |
# File 'lib/fractify/operator.rb', line 32 def decrease_rank!(number = 1) @rank -= number end |
#executed! ⇒ Object
40 41 42 |
# File 'lib/fractify/operator.rb', line 40 def executed! self.executed = true end |
#executed? ⇒ Boolean
44 45 46 |
# File 'lib/fractify/operator.rb', line 44 def executed? executed end |
#increase_rank!(number = 1) ⇒ Object
36 37 38 |
# File 'lib/fractify/operator.rb', line 36 def increase_rank!(number = 1) @rank += number end |
#not_executed? ⇒ Boolean
48 49 50 |
# File 'lib/fractify/operator.rb', line 48 def not_executed? !executed end |
#to_s ⇒ Object
28 29 30 |
# File 'lib/fractify/operator.rb', line 28 def to_s "(#{operator_character}, #{rank})" end |