Class: MultilangDocument

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

Overview

multilangdoc.rb

Copyright © 2003 Minero Aoki

This program is free software. You can distribute/modify this program under the terms of the GNU LGPL, Lesser General Public License version 2. For details of GNU LGPL, see the file “COPYING”.

$ docutils Id: multilangdoc.rb,v 1.4 2003/08/02 14:28:15 aamine Exp $

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(f, lang) ⇒ MultilangDocument

Returns a new instance of MultilangDocument.



24
25
26
27
28
29
# File 'lib/refe/multilangdoc.rb', line 24

def initialize( f, lang )
  @src = f
  @lang = lang
  @eof = false
  @on = true
end

Class Method Details

.extract(f, lang) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/refe/multilangdoc.rb', line 16

def MultilangDocument.extract( f, lang )
  buf = ''
  new(f,lang).each do |line|
    buf << line
  end
  buf
end

Instance Method Details

#eachObject



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/refe/multilangdoc.rb', line 50

def each
  @src.each do |line|
    case line
    when /\A([a-z])\s*\z/
      @on = ($1 == @lang[0,1])
    when /\A\.\s*\z/
      @on = true
    else
      yield line if @on
    end
  end
  @eof = true
end

#eof?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/refe/multilangdoc.rb', line 46

def eof?
  @eof
end

#getsObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/refe/multilangdoc.rb', line 31

def gets
  while line = @src.gets
    case line
    when /\A([a-z])\s*\z/
      @on = ($1 == @lang[0,1])
    when /\A\.\s*\z/
      @on = true
    else
      return line if @on
    end
  end
  @eof = true
  nil
end