Sha256: a9e993f85018220333d60128d162d61ef0fa2a74aba8b7e3cb366dcfac32dac4
Contents?: true
Size: 1.17 KB
Versions: 1
Compression:
Stored size: 1.17 KB
Contents
module Representable class Definition # :nodoc: attr_reader :name, :sought_type, :wrapper, :from alias_method :getter, :name def initialize(sym, options={}) @name = sym.to_s @array = options[:collection] @from = (options[:from] || name).to_s @sought_type = options[:as] || :text # FIXME: move me to xml. if options[:from].to_s =~ /^@/ @sought_type = :attr options[:from].sub!('@', '') end end def instance_variable_name :"@#{name}" end def setter :"#{name}=" end def typed? sought_type.is_a?(Class) end def name? @name == '*' end def content? @name == '.' end def array? @array end def cdata? # FIXME: move to XML! @cdata end # Applies the block to +value+ which might also be a collection. 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 end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
representable-0.9.3 | lib/representable/definition.rb |