Class: Linkterm::Document

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/linkterm.rb

Instance Method Summary collapse

Methods included from Enumerable

#partitions

Constructor Details

#initialize(text) ⇒ Document

Returns a new instance of Document.



166
167
168
# File 'lib/linkterm.rb', line 166

def initialize(text)
  @text = text
end

Instance Method Details

#eachObject



170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/linkterm.rb', line 170

def each
  ps = @text.gsub(/<.*?>|nbsp/, ' ').split(/(\r?\n\s*){2}/)
  # 短すぎるパラグラフは連結する
  ps2 = ps.inject(['']) {|result, item|
    (item.size > 150 ? result : result.last << ' ') << item
    result
  }

  ps2.each {|paragraph|
    yield Paragraph.new(paragraph)
  }
end