class SDL::Types::SDLSimpleType
Base SDL
type.
All types share a common constructor, which delegates part of its functionality.
Attributes
parent[RW]
The parent of this type.
parent_index[RW]
The index of this type instance in the parent list
raw_value[R]
The raw value, with which this type was instatiated
value[R]
The SDL
value type value, possibly converted to the wrapped ruby type, e.g., an URI object created from an “http://” String
Public Class Methods
new(raw_value)
click to toggle source
Creates a new instance of an SDL
type.
Invokes from_
methods of subtypes, if value
is not subtype of the wrapped Ruby type.
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.
# File lib/sdl/types/sdl_simple_type.rb, line 25 def initialize(raw_value) @raw_value = raw_value initialize_value end
Public Instance Methods
==(value)
click to toggle source
# File lib/sdl/types/sdl_simple_type.rb, line 43 def ==(value) @value == value end
annotated?()
click to toggle source
# File lib/sdl/types/sdl_simple_type.rb, line 51 def annotated? ! @annotations.blank? end
annotations()
click to toggle source
# File lib/sdl/types/sdl_simple_type.rb, line 55 def annotations @annotations ||= [] end
initialize_value()
click to toggle source
# 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_s()
click to toggle source
# File lib/sdl/types/sdl_simple_type.rb, line 47 def to_s @value.to_s end
Private Instance Methods
conversion_method_name(value)
click to toggle source
# File lib/sdl/types/sdl_simple_type.rb, line 66 def conversion_method_name(value) 'from_' + value.class.name.underscore.gsub('/', '_') end