Sha256: afe6153e4c960b57233c66991ec8b6134e4653d5605a70c163abbdd66ed18ecf

Contents?: true

Size: 1.2 KB

Versions: 3

Compression:

Stored size: 1.2 KB

Contents

module Caculo
  class JavascriptObject
    attr_accessor :javascript

    def initialize connection , name
      @connection = connection
      @javascript = "#{connection.caculo_object}.#{name}"
    end

    def val name
      obj = JavascriptObject.new( @connection , "" )
      obj.javascript = "#{@javascript}.#{name}"
      return obj
    end

    def val! name
      obj = JavascriptObject.new( @connection , "" )
      obj.javascript = "#{@javascript}.#{name}"
      return obj.execute
    end

    def method_missing name , *params
      obj = JavascriptObject.new( @connection , "" )

      js_parameters = params.map do |p|
        if p.kind_of? String
          "'#{p}'"
        else
          p.to_s
        end
      end

      obj.javascript = "#{@javascript}.#{name.to_s.gsub('!','').to_s}( #{js_parameters.join(',')} )"
      if name.to_s.match('!')
        return obj.execute
      else
        return obj
      end
    end

    def length
      obj = JavascriptObject.new( @connection , "" )
      obj.javascript = "#{@javascript}.length"
      return obj
    end

    def execute
      return @connection.send_command( "#{@javascript};" )
    end

    def to_s
      return @javascript
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cohitre-caculo-0.0.4 lib/caculo/javascript.rb
cohitre-caculo-0.0.6 lib/caculo/javascript.rb
cohitre-caculo-0.0.7 lib/caculo/javascript.rb