Class: GetText::RubyParser
- Inherits:
-
Object
- Object
- GetText::RubyParser
- Defined in:
- lib/gettext/tools/parser/ruby.rb
Defined Under Namespace
Classes: POExtractor
Class Method Summary collapse
-
.parse(path, options = {}) ⇒ Array<POEntry>
Parses Ruby script located at
path
. -
.target?(file) ⇒ Boolean
:nodoc:.
Instance Method Summary collapse
- #detect_encoding(source) ⇒ Object
-
#initialize(path, options = {}) ⇒ RubyParser
constructor
A new instance of RubyParser.
-
#parse ⇒ Array<POEntry>
Extracts messages from @path.
- #parse_source(source) ⇒ Object
Constructor Details
#initialize(path, options = {}) ⇒ RubyParser
Returns a new instance of RubyParser.
419 420 421 422 |
# File 'lib/gettext/tools/parser/ruby.rb', line 419 def initialize(path, ={}) @path = path @options = end |
Class Method Details
.parse(path, options = {}) ⇒ Array<POEntry>
Parses Ruby script located at path
.
This is a short cut method. It equals to new(path,
options).parse
.
348 349 350 351 |
# File 'lib/gettext/tools/parser/ruby.rb', line 348 def parse(path, ={}) parser = new(path, ) parser.parse end |
.target?(file) ⇒ Boolean
:nodoc:
334 335 336 |
# File 'lib/gettext/tools/parser/ruby.rb', line 334 def target?(file) # :nodoc: true # always true, as the default parser. end |
Instance Method Details
#detect_encoding(source) ⇒ Object
436 437 438 439 440 441 442 443 |
# File 'lib/gettext/tools/parser/ruby.rb', line 436 def detect_encoding(source) binary_source = source.dup.force_encoding("ASCII-8BIT") if /\A.*coding\s*[=:]\s*([[:alnum:]\-_]+)/ =~ binary_source $1.gsub(/-(?:unix|mac|dos)\z/, "") else nil end end |
#parse ⇒ Array<POEntry>
Extracts messages from @path.
427 428 429 430 431 432 433 434 |
# File 'lib/gettext/tools/parser/ruby.rb', line 427 def parse source = IO.read(@path) encoding = detect_encoding(source) || source.encoding source.force_encoding(encoding) parse_source(source) end |
#parse_source(source) ⇒ Object
445 446 447 448 449 450 451 452 |
# File 'lib/gettext/tools/parser/ruby.rb', line 445 def parse_source(source) extractor = POExtractor.new(source, @path) if @options.key?(:comment_tag) extractor.use_comment = true extractor.comment_tag = @options[:comment_tag] end extractor.parse([]) end |