-1

I'm trying to use the Linguist gem: https://github.com/github/linguist

My code is:

require 'linguist'

filePath = ARGV
langDetails = Linguist::FileBlob.new(filePath)
puts langDetails

That outputs: #<Linguist::FileBlob:0x007faf93b17200>

However, when I do puts langDetails.language, I get

/Users/myuser/.rvm/gems/ruby-1.9.3-p545@linguist/gems/github-linguist-2.10.15/lib/linguist/file_blob.rb:39:in `stat': can't convert Array into String (TypeError)
  from /Users/myuser/.rvm/gems/ruby-1.9.3-p545@linguist/gems/github-linguist-2.10.15/lib/linguist/file_blob.rb:39:in `mode'
  from /Users/myuser/.rvm/gems/ruby-1.9.3-p545@linguist/gems/github-linguist-2.10.15/lib/linguist/blob_helper.rb:294:in `language'
  from ./linguist.rb:9:in `<main>'

I'm not entirely sure what I'm doing wrong. Ideally I want the data back as a JSON object. How do I accomplish this?

Hooked
  • 84,485
  • 43
  • 192
  • 261
Shamoon
  • 41,293
  • 91
  • 306
  • 570

1 Answers1

2

Look at the source. FileBlog is saying File.stat(@path).mode.to_s(8) but @path is an array. filePath needs to be a path string, but ARGV is an array.

Perhaps you meant ARGV[0]?

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Great call! Thanks for the find. But now how do I get the results as a JSON object? – Shamoon May 12 '14 at 01:34
  • 1
    What results do you expect as a JSON object and why? I have never used Linguist but I don't see anything about that in the docs. It tells you what language your file is in. That's a string. How you expect Linguist to take you from "a Ruby object to JSON" is outside my understanding. You were getting an error, I explained it. – matt May 12 '14 at 02:03
  • 1
    If you want to turn a Ruby object to JSON, use the `to_json` method. But then I don't see what Linguist has to do with it. – matt May 12 '14 at 02:15