Class: ODDB::BsvXmlPlugin::Listener

Inherits:
Object
  • Object
show all
Includes:
REXML::StreamListener
Defined in:
src/plugin/bsv_xml.rb

Direct Known Subclasses

GenericsListener, ItCodesListener, PreparationsListener

Constant Summary

FORMATS =
{
  'b' => :bold,
  'i' => :italic,
}

Instance Method Summary (collapse)

Constructor Details

- (Listener) initialize(app, opts = {})

A new instance of Listener



29
# File 'src/plugin/bsv_xml.rb', line 29

def initialize app, opts={}

Instance Method Details

- (Object) date(txt)



34
35
36
37
38
39
# File 'src/plugin/bsv_xml.rb', line 34

def date txt
  unless txt.to_s.empty?
    parts = txt.split('.', 3).collect do |part| part.to_i end
    Date.new *parts.reverse
  end
end

- (Object) text(text)



40
41
42
43
44
45
# File 'src/plugin/bsv_xml.rb', line 40

def text text
  if @html
    @html << text.gsub(%r{<br\s*/?>}, "\n")
    @text = @html.gsub(%r{<[^>]+>}, '')
  end
end

- (Object) time(txt)



46
47
48
49
50
51
# File 'src/plugin/bsv_xml.rb', line 46

def time txt
  unless txt.to_s.empty?
    parts = txt.split('.', 3).collect do |part| part.to_i end
    Time.local *parts.reverse
  end
end

- (Object) update_chapter(chp, text, subheading = nil)



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'src/plugin/bsv_xml.rb', line 52

def update_chapter chp, text, subheading=nil
  sec = chp.next_section
  if subheading
    sec.subheading << subheading.to_s << "\n"
  end
  text.each do |line|
    par = sec.next_paragraph
    line.scan /(<(\/)?([bi])>|[^<]+|<)/u do |match|
      if fmt = FORMATS[match[2]]
        if match[1]
          par.reduce_format fmt
        else
          par.augment_format fmt
        end
      else
        par << match[0]
      end
    end
  end
  chp.clean!
end