Class: Zold::Remotes::Remote

Inherits:
Object
  • Object
show all
Defined in:
lib/zold/remotes.rb

Overview

One remote.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port, score) ⇒ Remote

Returns a new instance of Remote.



50
51
52
53
54
# File 'lib/zold/remotes.rb', line 50

def initialize(host, port, score)
  @host = host
  @port = port
  @score = score
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



49
50
51
# File 'lib/zold/remotes.rb', line 49

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



49
50
51
# File 'lib/zold/remotes.rb', line 49

def port
  @port
end

Instance Method Details

#assert_code(code, response) ⇒ Object



65
66
67
# File 'lib/zold/remotes.rb', line 65

def assert_code(code, response)
  raise "#{response.code} \"#{response.message}\" at \"#{response.body}\"" unless response.code.to_i == code
end

#assert_valid_score(score) ⇒ Object



69
70
71
72
# File 'lib/zold/remotes.rb', line 69

def assert_valid_score(score)
  raise "Invalid score #{score}" unless score.valid?
  raise "Expired score #{score}" if score.expired?
end

#http(path = '/') ⇒ Object



56
57
58
59
# File 'lib/zold/remotes.rb', line 56

def http(path = '/')
  uri = URI("http://#{@host}:#{@port}#{path}")
  Http.new(uri, @score)
end

#to_sObject



61
62
63
# File 'lib/zold/remotes.rb', line 61

def to_s
  "#{@host}:#{@port}"
end