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.



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

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

Instance Attribute Details

#hostObject

Returns the value of attribute host.



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

def host
  @host
end

#portObject

Returns the value of attribute port.



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

def port
  @port
end

#resultObject

Returns the value of attribute result.



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

def result
  @result
end

Class Method Details

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



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

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



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

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


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

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

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



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

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

#paragraph(txt, width = 70) ⇒ Object



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

def paragraph(txt, width=70)
  txt.each_line do |line|
    Textwrap.wrap(line, width).each { |chunk| text chunk }
  end
end

#text(text) ⇒ Object



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

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