Class: Synaptic4r::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/synaptic4r/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Result

.….….….….….….….….….….….….….….….….….….….….….….….….……



11
12
13
14
15
16
17
18
# File 'lib/synaptic4r/result.rb', line 11

def initialize(args)
  @http_request = args[:http_request]
  @headers = args[:headers]
  @url = args[:url]
  @sign =  args[:sign]
  @payload = args[:payload]
  @result = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &blk) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



25
26
27
28
29
30
31
# File 'lib/synaptic4r/result.rb', line 25

def method_missing(meth, *args, &blk)
  if result.kind_of?(Hash) and result.keys.include?(meth)
    result[meth]
  else
    result.send(meth, *args, &blk)
  end
end

Instance Attribute Details

#headersObject (readonly)

.….….….….….….….….….….….….….….….….….….….….….….….….……



8
9
10
# File 'lib/synaptic4r/result.rb', line 8

def headers
  @headers
end

#http_requestObject (readonly)

.….….….….….….….….….….….….….….….….….….….….….….….….……



8
9
10
# File 'lib/synaptic4r/result.rb', line 8

def http_request
  @http_request
end

#payloadObject (readonly)

.….….….….….….….….….….….….….….….….….….….….….….….….……



8
9
10
# File 'lib/synaptic4r/result.rb', line 8

def payload
  @payload
end

#resultObject (readonly)

.….….….….….….….….….….….….….….….….….….….….….….….….……



8
9
10
# File 'lib/synaptic4r/result.rb', line 8

def result
  @result
end

#signObject (readonly)

.….….….….….….….….….….….….….….….….….….….….….….….….……



8
9
10
# File 'lib/synaptic4r/result.rb', line 8

def sign
  @sign
end

#urlObject (readonly)

.….….….….….….….….….….….….….….….….….….….….….….….….……



8
9
10
# File 'lib/synaptic4r/result.rb', line 8

def url
  @url
end

Instance Method Details

#extract_header(args, header) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/synaptic4r/result.rb', line 34

def extract_header(args, header)
  headers = args[:result].headers[header]
  if headers
    headers.split(/,\s+/).map{|a| a.strip}.inject({}) do |r,a| 
      v = a.split('=')
      v << 'N/A' if v.length < 2
      r.update(v.first => v.last)
    end
  else
    {}
  end    
end

.….….….….….….….….….….….….….….….….….….….….….….….….……



21
22
# File 'lib/synaptic4r/result.rb', line 21

def print
end

#stringify_array(a) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



54
55
56
# File 'lib/synaptic4r/result.rb', line 54

def stringify_array(a)
  a.split(/,\s+/).sort.inject(""){|s,t| s += "#{t}, "}.chomp(', ') if a
end

#stringify_hash(h) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



48
49
50
# File 'lib/synaptic4r/result.rb', line 48

def stringify_hash(h)
  h.inject(""){|r,(u,a)| r += "  #{u}=#{a}\n"}
end