require 'observer' module Weskit::WML class Attribute < Item include Observable attachable_to :element attr_reader :value def code= bool @code = bool ? (@translatable = false ; true) : false end def code? @code end def multiline? "#{value}".include? "\n" end def text? code? or multiline? or translatable? end def translatable= bool @translatable = bool ? (@code = false ; true) : false end def translatable? @translatable end def initialize name, value, defaults = {} @code = @translatable = false self.name = name self.value = value merge defaults end def value= object @value = convert object end private def convert object string = object.to_s.strip object = case string when %r{^nil|null$} then nil when %r{^true|yes$} then true when %r{^false|no$} then false when %r{^[0-9]*\.[0-9]+$} then Float string when %r{^[0-9]+$} then Integer string else string end object.attr = self ; object end end end