Class: Agate::Parser
- Inherits:
-
Object
- Object
- Agate::Parser
- Defined in:
- lib/agate/parser.rb
Constant Summary collapse
- DEFAULTS =
Default options
{ :delimiters => "【】", :formatter => :plain }
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Parser
constructor
A new instance of Parser.
-
#parse(text) ⇒ Object
Parse ‘text` and return it with ruby character markup.
Constructor Details
Instance Method Details
#parse(text) ⇒ Object
Parse ‘text` and return it with ruby character markup
22 23 24 25 26 27 28 |
# File 'lib/agate/parser.rb', line 22 def parse(text) first = Regexp.escape(@options[:delimiters][0]) last = Regexp.escape(@options[:delimiters][-1]) expr = /(\p{Han}+)(#{first})([\p{Hiragana}\p{Katakana}]+)(#{last})/u text.gsub(expr) { |match| @formatter.format($~) } end |