Class: Code::Type::Repeat
- Inherits:
-
Code::Type
- Object
- Code::Type
- Code::Type::Repeat
- Defined in:
- lib/code/type/repeat.rb
Instance Attribute Summary collapse
-
#clazz ⇒ Object
readonly
Returns the value of attribute clazz.
-
#maximum ⇒ Object
readonly
Returns the value of attribute maximum.
-
#minimum ⇒ Object
readonly
Returns the value of attribute minimum.
Instance Method Summary collapse
-
#initialize(clazz, minimum: 0, maximum: nil) ⇒ Repeat
constructor
A new instance of Repeat.
- #max_arguments ⇒ Object
- #min_arguments ⇒ Object
- #name ⇒ Object
- #valid?(argument) ⇒ Boolean
Methods inherited from Code::Type
#max_arguments_of, #min_arguments_of, #valid_for?
Constructor Details
#initialize(clazz, minimum: 0, maximum: nil) ⇒ Repeat
Returns a new instance of Repeat.
8 9 10 11 12 |
# File 'lib/code/type/repeat.rb', line 8 def initialize(clazz, minimum: 0, maximum: nil) @clazz = clazz @minimum = minimum @maximum = maximum end |
Instance Attribute Details
#clazz ⇒ Object (readonly)
Returns the value of attribute clazz.
6 7 8 |
# File 'lib/code/type/repeat.rb', line 6 def clazz @clazz end |
#maximum ⇒ Object (readonly)
Returns the value of attribute maximum.
6 7 8 |
# File 'lib/code/type/repeat.rb', line 6 def maximum @maximum end |
#minimum ⇒ Object (readonly)
Returns the value of attribute minimum.
6 7 8 |
# File 'lib/code/type/repeat.rb', line 6 def minimum @minimum end |
Instance Method Details
#max_arguments ⇒ Object
22 23 24 25 |
# File 'lib/code/type/repeat.rb', line 22 def max_arguments max_arguments = max_arguments_of(clazz) max_arguments.nil? || maximum.nil? ? nil : maximum * max_arguments end |
#min_arguments ⇒ Object
18 19 20 |
# File 'lib/code/type/repeat.rb', line 18 def min_arguments minimum * min_arguments_of(clazz) end |
#name ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/code/type/repeat.rb', line 27 def name if minimum.zero? && maximum.nil? "#{clazz.name}.repeat" elsif maximum.nil? "#{clazz.name}.repeat(#{minimum})" else "#{clazz.name}.repeaa(#{minimum}, #{maximum})" end end |
#valid?(argument) ⇒ Boolean
14 15 16 |
# File 'lib/code/type/repeat.rb', line 14 def valid?(argument) valid_for?(expected: clazz, actual: argument) end |