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
SDLBoolean, SDLDescription, SDLDuration, SDLMoney, SDLNumber, SDLString, SDLTime, SDLUrl
Instance Attribute Summary collapse
-
#parent ⇒ Object
The parent of this type.
-
#parent_index ⇒ Object
The index of this type instance in the parent list.
-
#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
- #annotated? ⇒ Boolean
- #annotations ⇒ Object
-
#initialize(raw_value) ⇒ SDLSimpleType
constructor
Creates a new instance of an SDL type.
- #initialize_value ⇒ Object
- #to_s ⇒ Object
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
#parent ⇒ Object
The parent of this type.
63 64 65 |
# File 'lib/sdl/types/sdl_simple_type.rb', line 63 def parent @parent end |
#parent_index ⇒ Object
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_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
43 44 45 |
# File 'lib/sdl/types/sdl_simple_type.rb', line 43 def ==(value) @value == value end |
#annotated? ⇒ Boolean
51 52 53 |
# File 'lib/sdl/types/sdl_simple_type.rb', line 51 def annotated? ! @annotations.blank? end |
#annotations ⇒ Object
55 56 57 |
# File 'lib/sdl/types/sdl_simple_type.rb', line 55 def annotations @annotations ||= [] end |
#initialize_value ⇒ Object
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_s ⇒ Object
47 48 49 |
# File 'lib/sdl/types/sdl_simple_type.rb', line 47 def to_s @value.to_s end |