Class: As3gettext::Command
- Inherits:
-
Object
- Object
- As3gettext::Command
- Includes:
- GetText
- Defined in:
- lib/as3gettext/command.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
- #gettext ⇒ Object
-
#initialize ⇒ Command
constructor
A new instance of Command.
- #parse(argv) ⇒ Object
- #run(argv) ⇒ Object
- #xml ⇒ Object
Constructor Details
#initialize ⇒ Command
Returns a new instance of Command.
10 11 12 13 14 |
# File 'lib/as3gettext/command.rb', line 10 def initialize @config = { :mode => :gettext } end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
15 16 17 |
# File 'lib/as3gettext/command.rb', line 15 def config @config end |
Instance Method Details
#gettext ⇒ Object
22 23 24 25 |
# File 'lib/as3gettext/command.rb', line 22 def gettext RGetText.add_parser As3gettext::As3Parser GetText.rgettext config[:targets], config[:output] || STDOUT end |
#parse(argv) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/as3gettext/command.rb', line 38 def parse(argv) op = OptionParser.new op. = <<-EOF.gsub(/^\s+/, '') Usage: $ as3gettext src/HelloWrold.as src/**/*.mxml -o template.pot $ as3gettext i18n/**.po -x -o langs.xml EOF op.on('-h', '--help', 'show this message') { puts op; Kernel::exit 1 } op.on('-x', 'export XML') { config[:mode] = :xml } op.on('-o=VAL', 'output file') {|v| config[:output] = v } op.parse! argv if argv.length == 0 puts op exit 1 end config[:targets] = argv end |
#run(argv) ⇒ Object
17 18 19 20 |
# File 'lib/as3gettext/command.rb', line 17 def run(argv) parse argv send @config[:mode] end |
#xml ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/as3gettext/command.rb', line 27 def xml xml_string = GenerateXml.new.generate config[:targets] if config[:output] File.open(config[:output], 'w') do |f| f.puts xml_string end else puts xml_string end end |