Class: Oval::Collection
Overview
Declare container (e.g. array or hash).
Example 1: Desclare array of arbitrary elements:
Collection[Array]
or
Collection[Array,Anything[]]
or
Collection[InstanceOf[Array],Anything[]]
Example 2: Declare Array of Strings:
Collection[Array,InstanceOf[String]]
Example 3: Desclare any Hash:
Collection[Hash]
Example 4: Desclare Hash with Symbol keys and Fixnum values
Collection[Hash,{Symbol => Fixnum}]
Instance Attribute Summary collapse
-
#class_decl ⇒ Object
readonly
Returns the value of attribute class_decl.
-
#item_decl ⇒ Object
readonly
Returns the value of attribute item_decl.
-
#item_validator ⇒ Object
readonly
Returns the value of attribute item_validator.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(class_decl, item_decl = Oval::Anything[]) ⇒ Collection
constructor
A new instance of Collection.
- #klass ⇒ Object
- #validate(collection, subject = nil) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(class_decl, item_decl = Oval::Anything[]) ⇒ Collection
Returns a new instance of Collection.
58 59 60 61 |
# File 'lib/oval/collection.rb', line 58 def initialize(class_decl, item_decl = Oval::Anything[]) self.class_decl = class_decl self.item_decl = item_decl end |
Instance Attribute Details
#class_decl ⇒ Object
Returns the value of attribute class_decl.
71 72 73 |
# File 'lib/oval/collection.rb', line 71 def class_decl @class_decl end |
#item_decl ⇒ Object
Returns the value of attribute item_decl.
72 73 74 |
# File 'lib/oval/collection.rb', line 72 def item_decl @item_decl end |
#item_validator ⇒ Object (readonly)
Returns the value of attribute item_validator.
73 74 75 |
# File 'lib/oval/collection.rb', line 73 def item_validator @item_validator end |
Class Method Details
.[](class_decl, item_decl = Oval::Anything[]) ⇒ Object
54 55 56 |
# File 'lib/oval/collection.rb', line 54 def self.[](class_decl,item_decl = Oval::Anything[]) new(class_decl,item_decl) end |
.klass(class_decl) ⇒ Object
63 64 65 |
# File 'lib/oval/collection.rb', line 63 def self.klass(class_decl) class_decl.is_a?(Oval::SubclassOf) ? class_decl.klass : class_decl end |
Instance Method Details
#klass ⇒ Object
67 68 69 |
# File 'lib/oval/collection.rb', line 67 def klass self.class.klass(class_decl) end |
#validate(collection, subject = nil) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/oval/collection.rb', line 47 def validate(collection, subject = nil) class_subject = subject.nil? ? nil : "#{subject}.class" self.class.ensure_match(collection.class, class_decl, class_subject) i = 0 collection.each { |item| item_validator.validate(item, i, subject); i+= 1} end |