Class: Rouge::CLI::Guess

Inherits:
Rouge::CLI show all
Defined in:
lib/rouge/cli.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Rouge::CLI

class_from_arg, doc, error!, #error!, normalize_syntax

Constructor Details

#initialize(opts) ⇒ Guess

Returns a new instance of Guess.



491
492
493
494
# File 'lib/rouge/cli.rb', line 491

def initialize(opts)
  @input_file = opts[:input_file] || '-'
  @input_source = FileReader.new(@input_file).read
end

Instance Attribute Details

#input_fileObject (readonly)

Returns the value of attribute input_file.



489
490
491
# File 'lib/rouge/cli.rb', line 489

def input_file
  @input_file
end

#input_sourceObject (readonly)

Returns the value of attribute input_source.



489
490
491
# File 'lib/rouge/cli.rb', line 489

def input_source
  @input_source
end

Class Method Details

.descObject



481
482
483
# File 'lib/rouge/cli.rb', line 481

def self.desc
  "guess the languages of file"
end

.parse(args) ⇒ Object



485
486
487
# File 'lib/rouge/cli.rb', line 485

def self.parse(args)
  new(input_file: args.shift)
end

Instance Method Details

#lexersObject



496
497
498
499
500
501
# File 'lib/rouge/cli.rb', line 496

def lexers
  Lexer.guesses(
    filename: input_file,
    source: input_source,
  )
end

#runObject



503
504
505
506
507
# File 'lib/rouge/cli.rb', line 503

def run
  lexers.each do |l|
    puts "{ tag: #{l.tag.inspect}, title: #{l.title.inspect}, desc: #{l.desc.inspect} }"
  end
end