Sha256: f87cc2347e4393abddaba9d9e26a34e016c998aad09fb225f6597444c2d406d7

Contents?: true

Size: 1.73 KB

Versions: 26

Compression:

Stored size: 1.73 KB

Contents

module Ruby2JS
  class Converter

    # (ivar :@a)

    handle :ivar do |var|
      if self.ivars and self.ivars.include? var
        parse s(:hostvalue, self.ivars[var])
      elsif underscored_private
        parse s(:attr, s(:self), var.to_s.sub('@', '_'))
      else
        parse s(:attr, s(:self), var.to_s.sub('@', '#'))
      end
    end

    handle :hostvalue do |value|
      case value
      when Hash
        parse s(:hash, *value.map {|key, hvalue| 
          case key
          when String
            s(:pair, s(:str, key), s(:hostvalue, hvalue))
          when Symbol
            s(:pair, s(:sym, key), s(:hostvalue, hvalue))
          else
            s(:pair, s(:hostvalue, key), s(:hostvalue, hvalue))
          end
        })
      when Array
        parse s(:array, *value.map {|hvalue| s(:hostvalue, hvalue)})
      when String
        parse s(:str, value)
      when Integer
        parse s(:int, value)
      when Float
        parse s(:float, value)
      when true
        parse s(:true)
      when false
        parse s(:false)
      when nil
        parse s(:nil)
      when Symbol
        parse s(:sym, value)
      else
	value = value.as_json if value.respond_to?(:as_json)

        if value.respond_to?(:to_hash) and Hash === value.to_hash
	  parse s(:hostvalue, value.to_hash)
        elsif value.respond_to?(:to_ary) and Array === value.to_ary
	  parse s(:hostvalue, value.to_ary)
	elsif value.respond_to?(:to_str) and String === value.to_str
	  parse s(:str, value.to_str)
	elsif value.respond_to?(:to_int) and Integer === value.to_int
	  parse s(:int, value.to_int)
	elsif value.respond_to?(:to_sym) and Symbol === value.to_sym
	  parse s(:sym, value.to_sym)
	else
          parse s(:str, value.inspect)
	end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
ruby2js-5.1.1 lib/ruby2js/converter/ivar.rb
ruby2js-5.1.0 lib/ruby2js/converter/ivar.rb
ruby2js-5.0.1 lib/ruby2js/converter/ivar.rb
ruby2js-5.0.0 lib/ruby2js/converter/ivar.rb
ruby2js-4.2.2 lib/ruby2js/converter/ivar.rb
ruby2js-4.2.1 lib/ruby2js/converter/ivar.rb
ruby2js-4.2.0 lib/ruby2js/converter/ivar.rb
ruby2js-4.1.7 lib/ruby2js/converter/ivar.rb
ruby2js-4.1.6 lib/ruby2js/converter/ivar.rb
ruby2js-4.1.5 lib/ruby2js/converter/ivar.rb
ruby2js-4.1.4 lib/ruby2js/converter/ivar.rb
ruby2js-4.1.3 lib/ruby2js/converter/ivar.rb
ruby2js-4.1.2 lib/ruby2js/converter/ivar.rb
ruby2js-4.1.1 lib/ruby2js/converter/ivar.rb
ruby2js-4.1.0 lib/ruby2js/converter/ivar.rb
ruby2js-4.0.5 lib/ruby2js/converter/ivar.rb
ruby2js-4.0.4 lib/ruby2js/converter/ivar.rb
ruby2js-4.0.3 lib/ruby2js/converter/ivar.rb
ruby2js-4.0.2 lib/ruby2js/converter/ivar.rb
ruby2js-4.0.1 lib/ruby2js/converter/ivar.rb