Class: Finitio::SeqType

Inherits:
Type
  • Object
show all
Includes:
CollectionType
Defined in:
lib/finitio/type/seq_type.rb,
lib/finitio/generation/seq_type.rb,
lib/finitio/json_schema/seq_type.rb

Overview

The Seq type generator allows capturing sequences of values. For example, a (implicitely temporal) series of temperature measures could be written as:

Measures = [Temperature]

This class allows capturing those sequence types, e.g.:

Temperature = BuiltinType.new(Float)
Measures    = SeqType.new(Temperature)

An array of values is used as concrete representation for such sequences:

R(Measures) = Array[R(Temperature)] = Array[Float]

Accordingly, the ‘dress` transformation function has the signature below. It expects it’s Alpha/Object argument to be a object responding to ‘each` (with the ruby idiomatic semantics that such a `each` returns an Enumerator when invoked without block).

dress :: Alpha  -> Measures      throws TypeError
dress :: Object -> Array[Float]  throws TypeError

Constant Summary

Constants included from Metadata

Metadata::EMPTY_METADATA

Instance Attribute Summary

Attributes included from CollectionType

#elm_type

Instance Method Summary collapse

Methods included from CollectionType

#==, #hash, #initialize, #resolve_proxies, #suppremum, #unconstrained

Methods inherited from Type

#==, #anonymous?, #initialize, #name, #name=, #named?, #resolve_proxies, #suppremum, #to_s, #unconstrained

Methods included from Metadata

#metadata, #metadata=, #metadata?

Instance Method Details

#default_nameObject



50
51
52
# File 'lib/finitio/type/seq_type.rb', line 50

def default_name
  "[#{elm_type.name}]"
end

#dress(value, handler = DressHelper.new) ⇒ Object

Apply the element type’s ‘dress` transformation to each element of `value` (expected to respond to `each`). Return converted values in a ruby Array.



40
41
42
43
44
45
46
47
48
# File 'lib/finitio/type/seq_type.rb', line 40

def dress(value, handler = DressHelper.new)
  handler.failed!(self, value) unless value.respond_to?(:each)

  array = []
  handler.iterate(value) do |elm, index|
    array << elm_type.dress(elm, handler)
  end
  array
end

#generate_data(generator, world = nil) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/finitio/generation/seq_type.rb', line 4

def generate_data(generator, world = nil)
  coll = []
  generator.collection_size.times do
    coll << generator.call(elm_type, world)
  end
  coll
end

#include?(value) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/finitio/type/seq_type.rb', line 33

def include?(value)
  value.is_a?(::Array) and value.all?{|v| elm_type.include?(v) }
end

#representatorObject



29
30
31
# File 'lib/finitio/type/seq_type.rb', line 29

def representator
  [elm_type]
end

#to_json_schema(*args, &bl) ⇒ Object



4
5
6
7
8
9
# File 'lib/finitio/json_schema/seq_type.rb', line 4

def to_json_schema(*args, &bl)
  {
    type: "array",
    items: elm_type.to_json_schema(*args, &bl)
  }
end