Class: Oval::HashItem
Instance Attribute Summary collapse
-
#key_decl ⇒ Object
readonly
Returns the value of attribute key_decl.
-
#val_decl ⇒ Object
readonly
Returns the value of attribute val_decl.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(item_decl) ⇒ HashItem
constructor
A new instance of HashItem.
- #validate(item, i, subject = nil) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(item_decl) ⇒ HashItem
Returns a new instance of HashItem.
17 18 19 |
# File 'lib/oval/hash_item.rb', line 17 def initialize(item_decl) self.item_decl = item_decl end |
Instance Attribute Details
#key_decl ⇒ Object (readonly)
Returns the value of attribute key_decl.
21 22 23 |
# File 'lib/oval/hash_item.rb', line 21 def key_decl @key_decl end |
#val_decl ⇒ Object (readonly)
Returns the value of attribute val_decl.
22 23 24 |
# File 'lib/oval/hash_item.rb', line 22 def val_decl @val_decl end |
Class Method Details
.[](item_decl) ⇒ Object
13 14 15 |
# File 'lib/oval/hash_item.rb', line 13 def self.[](item_decl) new(item_decl) end |
.validate_item_decl(decl) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/oval/hash_item.rb', line 24 def self.validate_item_decl(decl) unless (decl.is_a?(Hash) and decl.size == 1) raise Oval::DeclError, "Invalid item declaration #{decl.inspect}. " + "Should be one-element Hash of type { key_decl => value_decl }" end end |
Instance Method Details
#validate(item, i, subject = nil) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/oval/hash_item.rb', line 6 def validate(item, i, subject = nil) key_subject = subject.nil? ? nil: "#{subject} key" val_subject = subject.nil? ? nil: "#{subject}[#{item[0].inspect}]" self.class.ensure_match(item[0],key_decl,key_subject) self.class.ensure_match(item[1],val_decl,val_subject) end |