Class: Gopher::MapContext

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port) ⇒ MapContext

Returns a new instance of MapContext.



192
193
194
195
# File 'lib/gopher.rb', line 192

def initialize(host, port)
  @host, @port = host, port
  @result = ""
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



190
191
192
# File 'lib/gopher.rb', line 190

def host
  @host
end

#portObject

Returns the value of attribute port.



190
191
192
# File 'lib/gopher.rb', line 190

def port
  @port
end

#resultObject

Returns the value of attribute result.



190
191
192
# File 'lib/gopher.rb', line 190

def result
  @result
end

Class Method Details

.with_block(host, port, *args, &block) ⇒ Object



197
198
199
# File 'lib/gopher.rb', line 197

def self.with_block(host, port, *args, &block)
  new(host, port).instance_exec(*args, &block)
end

Instance Method Details

#line(type, txt, selector, host = self.host, port = self.port) ⇒ Object



201
202
203
204
# File 'lib/gopher.rb', line 201

def line(type, txt, selector, host = self.host, port = self.port)
  result << ["#{type}#{txt}", selector, host, port].join("\t")
  result << "\r\n"
end


206
207
208
209
# File 'lib/gopher.rb', line 206

def link(text, selector, *args)
  type = Gopher.determine_type(selector)
  line type, text, scrub(selector), *args
end

#map(text, selector, *args) ⇒ Object



211
212
213
# File 'lib/gopher.rb', line 211

def map(text, selector, *args)
  line '1', text, scrub(selector), *args
end

#paragraph(txt, width = 70) ⇒ Object



219
220
221
222
223
# File 'lib/gopher.rb', line 219

def paragraph(txt, width=70)
  txt.each_line do |line|
    WordWrap.ww(line, width).each_line { |chunk| text chunk.strip }
  end
end

#text(text) ⇒ Object



215
216
217
# File 'lib/gopher.rb', line 215

def text(text)
  line 'i', text, 'false', '(NULL)', 0
end