lib/representable/definition.rb in representable-0.9.2 vs lib/representable/definition.rb in representable-0.9.3

- old
+ new

@@ -1,28 +1,20 @@ module Representable class Definition # :nodoc: attr_reader :name, :sought_type, :wrapper, :from alias_method :getter, :name - def initialize(sym, opts={}) - @name = sym.to_s + def initialize(sym, options={}) + @name = sym.to_s + @array = options[:collection] + @from = (options[:from] || name).to_s + @sought_type = options[:as] || :text - @array = true if opts[:as].is_a?(Array) # DISCUSS: move to ArrayDefinition. - @from = (opts[:from] || name).to_s - @sought_type = extract_type(opts[:as]) - # FIXME: move me to xml. - if opts[:from] == :content - opts[:from] = '.' - elsif opts[:from] == :name - opts[:from] = '*' - elsif opts[:from] == :attr + if options[:from].to_s =~ /^@/ @sought_type = :attr - opts[:from] = nil - elsif opts[:from].to_s =~ /^@/ - @sought_type = :attr - opts[:from].sub!('@', '') + options[:from].sub!('@', '') end end def instance_variable_name :"@#{name}" @@ -64,15 +56,8 @@ else value = yield value end value - end - - private - def extract_type(as) - as = as.first if as.is_a?(Array) # TODO: move to ArrayDefinition. - - as || :text end end end