Class: Tex2id::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/tex2id/cli.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



9
10
11
12
# File 'lib/tex2id/cli.rb', line 9

def initialize(argv)
  @argv = argv
  process_options
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



14
15
16
# File 'lib/tex2id/cli.rb', line 14

def argv
  @argv
end

#output_fileObject (readonly)

Returns the value of attribute output_file.



14
15
16
# File 'lib/tex2id/cli.rb', line 14

def output_file
  @output_file
end

#source_fileObject (readonly)

Returns the value of attribute source_file.



14
15
16
# File 'lib/tex2id/cli.rb', line 14

def source_file
  @source_file
end

Class Method Details

.run(argv) ⇒ Object



5
6
7
# File 'lib/tex2id/cli.rb', line 5

def self.run(argv)
  self.new(argv).run
end

Instance Method Details

#help(io) ⇒ Object



29
30
31
32
33
# File 'lib/tex2id/cli.rb', line 29

def help(io)
  io.puts <<-END_HELP
Usage: #{$0} <source_file> [<output_file>]
  END_HELP
end

#runObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/tex2id/cli.rb', line 16

def run
  unless source_file
    help($stdout)
    return 1
  end

  converter = Tex2id::Converter.new(source, only_fix_md2inao: @only_fix_md2inao)
  with_output_file_io do |io|
    io.write converter.convert
  end
  0
end