Class: AutoCorrect
- Inherits:
-
Object
show all
- Defined in:
- lib/auto-correct.rb,
lib/auto-correct/base.rb,
lib/auto-correct/html.rb,
lib/auto-correct/format.rb,
lib/auto-correct/string.rb,
lib/auto-correct/version.rb,
lib/auto-correct/strategery.rb
Defined Under Namespace
Modules: String
Classes: Strategery
Constant Summary
collapse
- CJK =
'\p{Han}|\p{Hangul}|\p{Hanunoo}|\p{Katakana}|\p{Hiragana}|\p{Bopomofo}'
- SPACE =
"[ ]"
- FULLDATE_RE =
/#{SPACE}{0,}\d+#{SPACE}{0,}年#{SPACE}{0,}\d+#{SPACE}{0,}月#{SPACE}{0,}\d+#{SPACE}{0,}[日号]#{SPACE}{0,}/u
- DASH_HAN_RE =
/([#{CJK})】」》”’])([\-]+)([#{CJK}(【「《“‘])/
- LEFT_QUOTE_RE =
/#{SPACE}([(【「《])/
- RIGHT_QUOTE_RE =
/([)】」》])#{SPACE}/
- VERSION =
"0.3.1"
- @@strategies =
[]
Class Method Summary
collapse
Class Method Details
25
26
27
28
29
30
31
32
33
|
# File 'lib/auto-correct/format.rb', line 25
def format(str)
out = str
self.strategies.each do |s|
out = s.format(out)
end
out = remove_full_date_spacing(out)
out = space_dash_with_hans(out)
out
end
|
5
6
7
8
9
10
11
12
|
# File 'lib/auto-correct/html.rb', line 5
def format_html(html)
doc = Nokogiri::HTML(html)
doc.traverse do |node|
next unless node.node_type == Nokogiri::XML::Node::TEXT_NODE
node.content = AutoCorrect.format(node.content)
end
doc.css("body").inner_html
end
|
.rule(one, other, space: false, reverse: false) ⇒ Object
5
6
7
|
# File 'lib/auto-correct/base.rb', line 5
def rule(one, other, space: false, reverse: false)
@@strategies << AutoCorrect::Strategery.new(one, other, space: space, reverse: reverse)
end
|
.strategies ⇒ Object
9
10
11
|
# File 'lib/auto-correct/base.rb', line 9
def strategies
@@strategies
end
|