Class: CodinRep::GetTime

Inherits:
Command show all
Defined in:
lib/codin_rep/get_time.rb

Constant Summary collapse

COMMAND_CODE =
"009b".freeze
EXPECTED_HEADER =
'REP008b'.freeze

Constants inherited from Command

Command::COMMAND_PREFIX

Instance Method Summary collapse

Methods inherited from Command

#execute, #generate_header, #get_max_attempts, #get_timeout_time, #initialize, #should_close_connection?

Constructor Details

This class inherits a constructor from CodinRep::Command

Instance Method Details

#check_response_headerObject



37
38
39
40
41
# File 'lib/codin_rep/get_time.rb', line 37

def check_response_header
  unless @response.match(/^#{EXPECTED_HEADER}/)
    raise UnknownHeader.new @response[0..6], 'get time', EXPECTED_HEADER
  end
end

#generate_command_payloadObject



29
30
31
# File 'lib/codin_rep/get_time.rb', line 29

def generate_command_payload
  ""
end

#get_data_from_response_payloadObject



47
48
49
50
51
52
53
54
55
# File 'lib/codin_rep/get_time.rb', line 47

def get_data_from_response_payload
  @time = nil
  begin
    @time = CodinRep::TimeUtil.unpack @response_payload
  rescue ArgumentError
    raise MalformedResponsePayload.new 'get time'
  end
  return [@time, Date.civil(1970,1,1), Date.civil(1970,1,1)]
end

#get_expected_response_sizeObject



33
34
35
# File 'lib/codin_rep/get_time.rb', line 33

def get_expected_response_size
  14
end

#get_response_payloadObject



43
44
45
# File 'lib/codin_rep/get_time.rb', line 43

def get_response_payload
  @response_payload = @response[7..-1]
end