Class: R0man::Digit
- Inherits:
-
Object
- Object
- R0man::Digit
- Defined in:
- lib/r0man/digit.rb
Defined Under Namespace
Classes: Invalid
Constant Summary collapse
- M =
new(name: "M", value: 1000, max_consecutive_allowed: 3, allowed_next_digits: [])
- D =
new(name: "D", value: 500, max_consecutive_allowed: 1, allowed_next_digits: [])
- C =
new(name: "C", value: 100, max_consecutive_allowed: 3, allowed_next_digits: [M, D])
- L =
new(name: "L", value: 50, max_consecutive_allowed: 1, allowed_next_digits: [])
- X =
new(name: "X", value: 10, max_consecutive_allowed: 3, allowed_next_digits: [C, L])
- V =
new(name: "V", value: 5, max_consecutive_allowed: 1, allowed_next_digits: [])
- I =
new(name: "I", value: 1, max_consecutive_allowed: 3, allowed_next_digits: [X, V])
- LOOKUP =
{ "I" => I, "V" => V, "X" => X, "L" => L, "C" => C, "D" => D, "M" => M, }
Instance Attribute Summary collapse
-
#allowed_next_digits ⇒ Object
readonly
Returns the value of attribute allowed_next_digits.
-
#max_consecutive_allowed ⇒ Object
readonly
Returns the value of attribute max_consecutive_allowed.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #allows_next_digit?(other_digit) ⇒ Boolean
- #greater_than?(other_digit) ⇒ Boolean
-
#initialize(options) ⇒ Digit
constructor
A new instance of Digit.
- #inspect ⇒ Object
- #to_s ⇒ Object
- #valid? ⇒ Boolean
- #value_compared_to(other_digit) ⇒ Object
Constructor Details
#initialize(options) ⇒ Digit
Returns a new instance of Digit.
5 6 7 8 9 10 |
# File 'lib/r0man/digit.rb', line 5 def initialize() @value = [:value] @name = [:name] @max_consecutive_allowed = [:max_consecutive_allowed] @allowed_next_digits = [:allowed_next_digits] end |
Instance Attribute Details
#allowed_next_digits ⇒ Object (readonly)
Returns the value of attribute allowed_next_digits.
3 4 5 |
# File 'lib/r0man/digit.rb', line 3 def allowed_next_digits @allowed_next_digits end |
#max_consecutive_allowed ⇒ Object (readonly)
Returns the value of attribute max_consecutive_allowed.
3 4 5 |
# File 'lib/r0man/digit.rb', line 3 def max_consecutive_allowed @max_consecutive_allowed end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/r0man/digit.rb', line 3 def name @name end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
3 4 5 |
# File 'lib/r0man/digit.rb', line 3 def value @value end |
Class Method Details
Instance Method Details
#allows_next_digit?(other_digit) ⇒ Boolean
32 33 34 |
# File 'lib/r0man/digit.rb', line 32 def allows_next_digit?(other_digit) allowed_next_digits.include?(other_digit) end |
#greater_than?(other_digit) ⇒ Boolean
24 25 26 |
# File 'lib/r0man/digit.rb', line 24 def greater_than?(other_digit) value > other_digit.value end |
#inspect ⇒ Object
20 21 22 |
# File 'lib/r0man/digit.rb', line 20 def inspect to_s end |
#to_s ⇒ Object
16 17 18 |
# File 'lib/r0man/digit.rb', line 16 def to_s "#{name}(#{value})" end |
#valid? ⇒ Boolean
12 13 14 |
# File 'lib/r0man/digit.rb', line 12 def valid? true end |
#value_compared_to(other_digit) ⇒ Object
28 29 30 |
# File 'lib/r0man/digit.rb', line 28 def value_compared_to(other_digit) other_digit.greater_than?(self) ? -value : value end |