Class: Oval::HashItem

Inherits:
Base
  • Object
show all
Defined in:
lib/oval/hash_item.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

ensure_equal, ensure_match

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_declObject (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_declObject (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