Class: I18n::Translate::Processor::Template
- Inherits:
-
Object
- Object
- I18n::Translate::Processor::Template
- Defined in:
- lib/i18n/processor.rb
Overview
this is abstract class for processors. processors should mainly implement protected methdos import and export
Direct Known Subclasses
Gettext, Properties, Ruby, TS, YAML
Constant Summary collapse
- FORMAT =
[]
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#translate ⇒ Object
readonly
Returns the value of attribute translate.
Class Method Summary collapse
-
.can_handle?(fname) ⇒ Boolean
check if processor can handle this file.
-
.inherited(processor) ⇒ Object
register new processor.
-
.register(default = 'yml') ⇒ Object
register proessors’s formats.
Instance Method Summary collapse
-
#initialize(fname, tr) ⇒ Template
constructor
initialize new processor.
-
#read ⇒ Object
read file into hash.
-
#write(data) ⇒ Object
write hash to file.
Constructor Details
#initialize(fname, tr) ⇒ Template
initialize new processor
65 66 67 68 69 70 |
# File 'lib/i18n/processor.rb', line 65 def initialize(fname, tr) @filename = fname @translate = tr fname =~ %r{/?([^/]+)\.[^\.]+$}i @lang = $1.to_s.strip end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
62 63 64 |
# File 'lib/i18n/processor.rb', line 62 def filename @filename end |
#translate ⇒ Object (readonly)
Returns the value of attribute translate.
62 63 64 |
# File 'lib/i18n/processor.rb', line 62 def translate @translate end |
Class Method Details
.can_handle?(fname) ⇒ Boolean
check if processor can handle this file
104 105 106 107 |
# File 'lib/i18n/processor.rb', line 104 def self.can_handle?(fname) fname =~ %r{\.([^\.]+)$}i self::FORMAT.include?($1) end |
.inherited(processor) ⇒ Object
register new processor
58 59 60 |
# File 'lib/i18n/processor.rb', line 58 def self.inherited(processor) Processor << processor end |
.register(default = 'yml') ⇒ Object
register proessors’s formats
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/i18n/processor.rb', line 73 def self.register(default='yml') self::FORMAT.each do |format| unless I18n::Translate::FORMATS.include?(format) # default format will be first if default == format I18n::Translate::FORMATS.unshift(format) else I18n::Translate::FORMATS << format end end end end |
Instance Method Details
#read ⇒ Object
read file into hash
87 88 89 90 91 92 93 |
# File 'lib/i18n/processor.rb', line 87 def read data = File.open(@filename, mode("r")) do |f| f.flock File::LOCK_SH f.read end import(data) end |
#write(data) ⇒ Object
write hash to file
96 97 98 99 100 101 |
# File 'lib/i18n/processor.rb', line 96 def write(data) File.open(@filename, mode("w")) do |f| f.flock File::LOCK_EX f << export(data) end end |