Class: Representable::Definition
- Inherits:
-
Object
- Object
- Representable::Definition
- Defined in:
- lib/representable/definition.rb
Overview
:nodoc:
Direct Known Subclasses
Instance Attribute Summary collapse
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#name ⇒ Object
(also: #getter)
readonly
Returns the value of attribute name.
-
#sought_type ⇒ Object
readonly
Returns the value of attribute sought_type.
-
#wrapper ⇒ Object
readonly
Returns the value of attribute wrapper.
Instance Method Summary collapse
-
#apply(value) ⇒ Object
Applies the block to
value
which might also be a collection. - #array? ⇒ Boolean
-
#cdata? ⇒ Boolean
FIXME: move to XML!.
- #content? ⇒ Boolean
-
#initialize(sym, options = {}) ⇒ Definition
constructor
A new instance of Definition.
- #instance_variable_name ⇒ Object
- #name? ⇒ Boolean
- #setter ⇒ Object
- #typed? ⇒ Boolean
Constructor Details
#initialize(sym, options = {}) ⇒ Definition
Returns a new instance of Definition.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/representable/definition.rb', line 6 def initialize(sym, ={}) @name = sym.to_s @array = [:collection] @from = ([:from] || name).to_s @sought_type = [:as] || :text # FIXME: move me to xml. if [:from].to_s =~ /^@/ @sought_type = :attr [:from].sub!('@', '') end end |
Instance Attribute Details
#from ⇒ Object (readonly)
Returns the value of attribute from.
3 4 5 |
# File 'lib/representable/definition.rb', line 3 def from @from end |
#name ⇒ Object (readonly) Also known as: getter
Returns the value of attribute name.
3 4 5 |
# File 'lib/representable/definition.rb', line 3 def name @name end |
#sought_type ⇒ Object (readonly)
Returns the value of attribute sought_type.
3 4 5 |
# File 'lib/representable/definition.rb', line 3 def sought_type @sought_type end |
#wrapper ⇒ Object (readonly)
Returns the value of attribute wrapper.
3 4 5 |
# File 'lib/representable/definition.rb', line 3 def wrapper @wrapper end |
Instance Method Details
#apply(value) ⇒ Object
Applies the block to value
which might also be a collection.
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/representable/definition.rb', line 49 def apply(value) return value unless value # DISCUSS: is that ok here? if array? value = value.collect do |item| yield item end else value = yield value end value end |
#array? ⇒ Boolean
39 40 41 |
# File 'lib/representable/definition.rb', line 39 def array? @array end |
#cdata? ⇒ Boolean
FIXME: move to XML!
43 44 45 |
# File 'lib/representable/definition.rb', line 43 def cdata? # FIXME: move to XML! @cdata end |
#content? ⇒ Boolean
35 36 37 |
# File 'lib/representable/definition.rb', line 35 def content? @name == '.' end |
#instance_variable_name ⇒ Object
19 20 21 |
# File 'lib/representable/definition.rb', line 19 def instance_variable_name :"@#{name}" end |
#name? ⇒ Boolean
31 32 33 |
# File 'lib/representable/definition.rb', line 31 def name? @name == '*' end |
#setter ⇒ Object
23 24 25 |
# File 'lib/representable/definition.rb', line 23 def setter :"#{name}=" end |
#typed? ⇒ Boolean
27 28 29 |
# File 'lib/representable/definition.rb', line 27 def typed? sought_type.is_a?(Class) end |