Class: Treyja::Exe

Inherits:
Object
  • Object
show all
Defined in:
lib/treyja/exe.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Exe

Returns a new instance of Exe.



28
29
30
# File 'lib/treyja/exe.rb', line 28

def initialize args
  @args = args
end

Instance Method Details

#optionsObject



32
33
34
# File 'lib/treyja/exe.rb', line 32

def options
  @options ||= {}
end

#patch_round(round) ⇒ Object



36
37
38
39
40
# File 'lib/treyja/exe.rb', line 36

def patch_round round
  if round > 0
    ::Float.instance_variable_set "@round_digits", round
  end
end

#runObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/treyja/exe.rb', line 42

def run
  opts = OptionParser.new
  opts.on("--output DIR")
  opts.on("--normalize")
  opts.on("--round INT")
  opts.on("--version") do
    puts "Version: #{Treyja::VERSION}"
    return
  end
  opts.on("-h", "--help") do
    Treyja::Command::Help.new.run
    return
  end
  command, file = opts.parse!(@args, into: options)

  patch_round options.fetch(:round, 4).to_f
  case command
  when "dump"
    reader = Treyja::Reader.new file
    Treyja::Command::Dump.new(reader).run
  when "json"
    reader = Treyja::Reader.new file
    Treyja::Command::Json.new(reader).run
  when "image"
    output_dir = options[:output]
    raise "--output option required" unless output_dir

    reader = Treyja::Reader.new file
    Treyja::Command::Image.new(reader, output_dir, options.slice(:normalize)).run
  when "csv"
    reader = Treyja::Reader.new file
    Treyja::Command::Csv.new(reader).run
  when nil
    Treyja::Command::Help.new.run
  else
    puts "Unknown command: #{command}"
    Treyja::Command::Help.new.run
  end
end