Class: MassiveSitemap::Writer::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/massive_sitemap/writer/base.rb

Direct Known Subclasses

File, String

Constant Summary collapse

OPTS =
{}

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



12
13
14
15
# File 'lib/massive_sitemap/writer/base.rb', line 12

def initialize(options = {})
  @options = self.class::OPTS.merge(options)
  @stream  = nil
end

Instance Method Details

#close!Object

close writer (e.g store file)



35
36
37
38
39
40
# File 'lib/massive_sitemap/writer/base.rb', line 35

def close!
  if inited?
    close_stream(@stream)
    @stream = nil
  end
end

#currentObject



56
57
58
# File 'lib/massive_sitemap/writer/base.rb', line 56

def current
  stream_id
end

#each(&block) ⇒ Object



52
53
54
# File 'lib/massive_sitemap/writer/base.rb', line 52

def each(&block)
  stream_ids.each(&block)
end

#init!(options = {}) ⇒ Object

init writer: try to open stream (e.g. file)



27
28
29
30
31
32
# File 'lib/massive_sitemap/writer/base.rb', line 27

def init!(options = {})
  set(options)
  if init?
    @stream = open_stream
  end
end

#inited?Boolean

keep status of stream

Returns:

  • (Boolean)


43
44
45
# File 'lib/massive_sitemap/writer/base.rb', line 43

def inited?
  @stream
end

write to stream



48
49
50
# File 'lib/massive_sitemap/writer/base.rb', line 48

def print(string)
  @stream.print(string) if inited?
end

#set(options) ⇒ Object

API to which a builder talks to

update wirter options, e.g. filename or overwrite behavior



21
22
23
24
# File 'lib/massive_sitemap/writer/base.rb', line 21

def set(options)
  @options.merge!(options)
  self
end