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, it_should, validate

Constructor Details

#initialize(item_decl) ⇒ HashItem

Returns a new instance of HashItem.


22
23
24
# File 'lib/oval/hash_item.rb', line 22

def initialize(item_decl)
  self.item_decl = item_decl
end

Instance Attribute Details

#key_declObject (readonly)

Returns the value of attribute key_decl


26
27
28
# File 'lib/oval/hash_item.rb', line 26

def key_decl
  @key_decl
end

#val_declObject (readonly)

Returns the value of attribute val_decl


27
28
29
# File 'lib/oval/hash_item.rb', line 27

def val_decl
  @val_decl
end

Class Method Details

.[](item_decl) ⇒ Object


18
19
20
# File 'lib/oval/hash_item.rb', line 18

def self.[](item_decl)
  new(item_decl)
end

.validate_item_decl(decl) ⇒ Object


29
30
31
32
33
34
# File 'lib/oval/hash_item.rb', line 29

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

#it_shouldObject


13
14
15
16
# File 'lib/oval/hash_item.rb', line 13

def it_should
  "be {key => value} where key should #{self.class.it_should(key_decl)} " +
  "and value should #{self.class.it_should(val_decl)}"
end

#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.validate(item[0],key_decl,key_subject)
  self.class.validate(item[1],val_decl,val_subject)
end