Class: JSTP::Dispatch

Inherits:
Hash
  • Object
show all
Includes:
Discoverer::Reader, Discoverer::Writer
Defined in:
lib/jstp/dispatch.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Dispatch

Returns a new instance of Dispatch.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/jstp/dispatch.rb', line 6

def initialize *args
  
  unless args.empty?
    if args.length == 1
      if args.first.is_a? Hash
        from.hash args.first
      elsif args.first.is_a? String
        from.string args.first
      elsif args.first.is_a? Symbol
        self.method = args.first
      end
    else
      from.array args
    end
  end

  self["protocol"] = ["JSTP", "0.1"] unless self.has_key? "protocol"
  self["timestamp"] = Time.now.to_i
end

Instance Method Details

#bodyObject



98
99
100
# File 'lib/jstp/dispatch.rb', line 98

def body
  self["body"]
end

#body=(the_body) ⇒ Object



102
103
104
# File 'lib/jstp/dispatch.rb', line 102

def body= the_body
  self["body"] = the_body
end

#gatewayObject



106
107
108
# File 'lib/jstp/dispatch.rb', line 106

def gateway
  self["gateway"]
end

#gateway=(the_gateway) ⇒ Object



110
111
112
# File 'lib/jstp/dispatch.rb', line 110

def gateway= the_gateway
  self["gateway"] = the_gateway
end

#methodObject



30
31
32
# File 'lib/jstp/dispatch.rb', line 30

def method
  self["method"]
end

#method=(the_method) ⇒ Object



34
35
36
# File 'lib/jstp/dispatch.rb', line 34

def method= the_method
  self["method"] = the_method.to_s.upcase
end

#protocolObject



50
51
52
# File 'lib/jstp/dispatch.rb', line 50

def protocol
  self["protocol"]
end

#protocol=(the_protocol) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/jstp/dispatch.rb', line 54

def protocol= the_protocol
  if the_protocol.is_a? Array
    self["protocol"] = the_protocol
  elsif the_protocol.is_a? String 
    self["protocol"] = the_protocol.split "/"
  end
end

#refererObject



74
75
76
# File 'lib/jstp/dispatch.rb', line 74

def referer
  self["referer"]
end

#referer=(the_referer) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/jstp/dispatch.rb', line 78

def referer= the_referer
  if the_referer.is_a? Array
    self["referer"] = the_referer
  elsif the_referer.is_a? String 
    self["referer"] = the_referer.split "/"
  end
end

#resourceObject



38
39
40
# File 'lib/jstp/dispatch.rb', line 38

def resource
  self["resource"]
end

#resource=(the_resource) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/jstp/dispatch.rb', line 42

def resource= the_resource
  if the_resource.is_a? Array
    self["resource"] = the_resource
  elsif the_resource.is_a? String
    self["resource"] = the_resource.split "/"
  end
end

#timestampObject



62
63
64
# File 'lib/jstp/dispatch.rb', line 62

def timestamp
  self["timestamp"]
end

#timestamp=(the_timestamp) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/jstp/dispatch.rb', line 66

def timestamp= the_timestamp
  if the_timestamp.is_a? Integer
    self["timestamp"] = the_timestamp
  elsif the_timestamp.is_a? Time
    self["timestamp"] = the_timestamp.to_i
  end
end

#to_sObject



26
27
28
# File 'lib/jstp/dispatch.rb', line 26

def to_s
  to.string
end

#tokenObject



86
87
88
# File 'lib/jstp/dispatch.rb', line 86

def token
  self["token"]
end

#token=(the_token) ⇒ Object



90
91
92
93
94
95
96
# File 'lib/jstp/dispatch.rb', line 90

def token= the_token
  if the_token.is_a? Array
    self["token"] = the_token
  elsif the_token.is_a? String 
    self["token"] = the_token.split "/"
  end
end