Class: SDL::Types::SDLSimpleType
- Inherits:
-
Object
- Object
- SDL::Types::SDLSimpleType
- 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.
Direct Known Subclasses
SDLDatetime, SDLDescription, SDLDuration, SDLNumber, SDLString, SDLUrl
Instance Attribute Summary collapse
-
#raw_value ⇒ Object
readonly
The raw value, with which this type was instatiated.
-
#value ⇒ Object
readonly
The SDL value type value, possibly converted to the wrapped ruby type, e.g., an URI object created from an “http://” String.
Instance Method Summary collapse
- #==(value) ⇒ Object
-
#initialize(value) ⇒ SDLSimpleType
constructor
Creates a new instance of an SDL type.
- #to_s ⇒ Object
Methods included from SDLType
Constructor Details
#initialize(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 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 30 31 32 33 34 35 36 37 |
# File 'lib/sdl/types/sdl_simple_type.rb', line 25 def initialize(value) @raw_value = value if value.class <= self.class.wrapped_type @value = value else begin send(conversion_method_name(value), value) rescue NoMethodError raise "Cannot create instance of #{self.class.name} with a #{value.class.name} value. Please implement #{self.class.name}##{conversion_method_name(value)}" end end end |
Instance Attribute Details
#raw_value ⇒ Object (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 |
#value ⇒ Object (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
39 40 41 |
# File 'lib/sdl/types/sdl_simple_type.rb', line 39 def ==(value) @value == value end |
#to_s ⇒ Object
43 44 45 |
# File 'lib/sdl/types/sdl_simple_type.rb', line 43 def to_s @value.to_s end |