Class: SDL::Types::SDLSimpleType

Inherits:
Object
  • Object
show all
Includes:
SDLType
Defined in:
lib/sdl/types/sdl_simple_type.rb

Overview

Base SDL type.

All types share a common constructor, which delegates part of its functionality.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SDLType

codes, included, #xml_attributes, #xml_value

Constructor Details

#initialize(raw_value) ⇒ SDLSimpleType

Creates a new instance of an SDL type.

Invokes from_ methods of subtypes, if value is not subtype of the wrapped Ruby type.

@param raw_value

The instance value. Unless the value class is a subclass of the wrapped Ruby class,
perform conversion by invoking +from_#{classname}+, e.g. +from_string+ or +from_integer+.

Subclasses are expected to implement this conversion function.


25
26
27
28
29
# File 'lib/sdl/types/sdl_simple_type.rb', line 25

def initialize(raw_value)
  @raw_value = raw_value

  initialize_value
end

Instance Attribute Details

#parentObject

The parent of this type.



63
64
65
# File 'lib/sdl/types/sdl_simple_type.rb', line 63

def parent
  @parent
end

#parent_indexObject

The index of this type instance in the parent list



60
61
62
# File 'lib/sdl/types/sdl_simple_type.rb', line 60

def parent_index
  @parent_index
end

#raw_valueObject (readonly)

The raw value, with which this type was instatiated



13
14
15
# File 'lib/sdl/types/sdl_simple_type.rb', line 13

def raw_value
  @raw_value
end

#valueObject (readonly)

The SDL value type value, possibly converted to the wrapped ruby type, e.g., an URI object created from an “http://” String



10
11
12
# File 'lib/sdl/types/sdl_simple_type.rb', line 10

def value
  @value
end

Instance Method Details

#==(value) ⇒ Object



43
44
45
# File 'lib/sdl/types/sdl_simple_type.rb', line 43

def ==(value)
  @value == value
end

#annotated?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/sdl/types/sdl_simple_type.rb', line 51

def annotated?
  ! @annotations.blank?
end

#annotationsObject



55
56
57
# File 'lib/sdl/types/sdl_simple_type.rb', line 55

def annotations
  @annotations ||= []
end

#initialize_valueObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sdl/types/sdl_simple_type.rb', line 31

def initialize_value
  if raw_value.class <= self.class.wrapped_type
    @value = raw_value
  else
    begin
      send(conversion_method_name(raw_value), raw_value)
    rescue NoMethodError
      raise "Cannot create instance of #{self.class.name} with a #{raw_value.class.name} value. Please implement #{self.class.name}##{conversion_method_name(raw_value)}"
    end
  end
end

#to_sObject



47
48
49
# File 'lib/sdl/types/sdl_simple_type.rb', line 47

def to_s
  @value.to_s
end