Class: Pact::ArrayLike

Inherits:
Object
  • Object
show all
Includes:
SymbolizeKeys
Defined in:
lib/pact/array_like.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SymbolizeKeys

included, #symbolize_keys

Constructor Details

#initialize(contents, options = {}) ⇒ ArrayLike

Returns a new instance of ArrayLike.



9
10
11
12
# File 'lib/pact/array_like.rb', line 9

def initialize contents, options = {}
  @contents = contents
  @min = options[:min] || 1
end

Instance Attribute Details

#contentsObject (readonly)

Returns the value of attribute contents.



6
7
8
# File 'lib/pact/array_like.rb', line 6

def contents
  @contents
end

#minObject (readonly)

Returns the value of attribute min.



7
8
9
# File 'lib/pact/array_like.rb', line 7

def min
  @min
end

Class Method Details

.json_create(hash) ⇒ Object



30
31
32
33
# File 'lib/pact/array_like.rb', line 30

def self.json_create hash
  symbolized_hash = symbolize_keys(hash)
  new(symbolized_hash[:contents], {min: symbolized_hash[:min]})
end

Instance Method Details

#==(other) ⇒ Object



39
40
41
# File 'lib/pact/array_like.rb', line 39

def == other
  other.is_a?(ArrayLike) && other.contents == self.contents && other.min == self.min
end

#as_json(opts = {}) ⇒ Object



22
23
24
# File 'lib/pact/array_like.rb', line 22

def as_json opts = {}
  to_hash
end

#eq(other) ⇒ Object



35
36
37
# File 'lib/pact/array_like.rb', line 35

def eq other
  self == other
end

#generateObject



43
44
45
# File 'lib/pact/array_like.rb', line 43

def generate
  min.times.collect{ Pact::Reification.from_term contents }
end

#to_hashObject



14
15
16
17
18
19
20
# File 'lib/pact/array_like.rb', line 14

def to_hash
  {
    :json_class => self.class.name,
    :contents => contents,
    :min => min
  }
end

#to_json(opts = {}) ⇒ Object



26
27
28
# File 'lib/pact/array_like.rb', line 26

def to_json opts = {}
  as_json.to_json opts
end