Class: Qrb::Type

Inherits:
Object
  • Object
show all
Defined in:
lib/qrb/type.rb

Overview

Abstract class for Q type (generators).

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Type

Returns a new instance of Type.



7
8
9
10
11
12
# File 'lib/qrb/type.rb', line 7

def initialize(name)
  unless name.nil? or name.is_a?(String)
    raise ArgumentError, "String expected for type name, got `#{name}`"
  end
  @name = name
end

Instance Method Details

#dress(*args) ⇒ Object

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/qrb/type.rb', line 40

def dress(*args)
  raise NotImplementedError, "Missing #{self.class.name}#dress"
end

#include?(value) ⇒ Boolean

Check if ‘value` belongs to this type. Returns true if it’s the case, false otherwise.

For belonging to the type, ‘value` MUST be a valid representation, not an ’approximation’ or some ‘similar’ representation. In particular, returning true means that no dressing is required for using ‘value` as a proper one. Similarly, the method MUST always return true on a value directly obtained through `dress`.

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


36
37
38
# File 'lib/qrb/type.rb', line 36

def include?(value)
  raise NotImplementedError, "Missing #{self.class.name}#include?"
end

#nameObject



14
15
16
# File 'lib/qrb/type.rb', line 14

def name
  @name || default_name
end

#name=(n) ⇒ Object

Raises:



18
19
20
21
# File 'lib/qrb/type.rb', line 18

def name=(n)
  raise Error, "Name already set to `#{@name}`" unless @name.nil?
  @name = n
end

#to_sObject



23
24
25
# File 'lib/qrb/type.rb', line 23

def to_s
  name.to_s
end