Class: TTK::Fetchers::Client::Receiver

Inherits:
Object
  • Object
show all
Includes:
DRb::DRbUndumped
Defined in:
lib/ttk/fetchers/client/receiver.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ Receiver

Returns a new instance of Receiver.



17
18
19
20
21
22
23
# File 'lib/ttk/fetchers/client/receiver.rb', line 17

def initialize(resource)
  @resource = resource
  @file = @resource.open('w')
  @md5sum = Digest::MD5.new
  @t0 = Time.now
  @success = nil
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



25
26
27
# File 'lib/ttk/fetchers/client/receiver.rb', line 25

def resource
  @resource
end

Instance Method Details

#recv(str) ⇒ Object



27
28
29
30
# File 'lib/ttk/fetchers/client/receiver.rb', line 27

def recv(str)
  @md5sum << str
  @file.write(str)
end

#statObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/ttk/fetchers/client/receiver.rb', line 38

def stat
  unless @success.nil?
    {
      :resource => @resource,
      :enlapsed_time => @enlapsed_time,
      :md5sum => @md5sum.to_s,
      :success => @success
    }
  end
end

#stop(md5sum) ⇒ Object



32
33
34
35
36
# File 'lib/ttk/fetchers/client/receiver.rb', line 32

def stop(md5sum)
  @file.close
  @enlapsed_time = DTime.new(Time.now - @t0)
  @success = (@md5sum.to_s == md5sum)
end