language_sniffer 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,71 @@
1
+ require 'language_sniffer/language'
2
+
3
+ module LanguageSniffer
4
+ # Similar to ::Pathname, LanguageSniffer::Pathname wraps a path string and
5
+ # provides helpful query methods. Its useful when you only have a
6
+ # filename but not a blob and need to figure out the language of the file.
7
+ class Pathname
8
+ # Public: Initialize a Pathname
9
+ #
10
+ # path - A filename String. The file may or maybe actually exist.
11
+ #
12
+ # Returns a Pathname.
13
+ def initialize(path)
14
+ @path = path
15
+ end
16
+
17
+ # Public: Get the basename of the path
18
+ #
19
+ # Examples
20
+ #
21
+ # Pathname.new('sub/dir/file.rb').basename
22
+ # # => 'file.rb'
23
+ #
24
+ # Returns a String.
25
+ def basename
26
+ File.basename(@path)
27
+ end
28
+
29
+ # Public: Get the extname of the path
30
+ #
31
+ # Examples
32
+ #
33
+ # Pathname.new('.rb').extname
34
+ # # => '.rb'
35
+ #
36
+ # Pathname.new('file.rb').extname
37
+ # # => '.rb'
38
+ #
39
+ # Returns a String.
40
+ def extname
41
+ File.extname(@path)
42
+ end
43
+
44
+ # Public: Get the language of the path
45
+ #
46
+ # The path extension name is the only heuristic used to detect the
47
+ # language name.
48
+ #
49
+ # Examples
50
+ #
51
+ # Pathname.new('file.rb').language
52
+ # # => Language['Ruby']
53
+ #
54
+ # Returns a Language or nil if none was found.
55
+ def language
56
+ @language ||= Language.find_by_filename(@path)
57
+ end
58
+
59
+ # Public: Return self as String
60
+ #
61
+ # Returns a String
62
+ def to_s
63
+ @path.dup
64
+ end
65
+
66
+ def eql?(other)
67
+ other.is_a?(self.class) && @path == other.to_s
68
+ end
69
+ alias_method :==, :eql?
70
+ end
71
+ end
@@ -0,0 +1,8 @@
1
+ module LanguageSniffer
2
+ module Version
3
+ MAJOR = 1
4
+ MINOR = 0
5
+ PATCH = 0
6
+ STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ require 'language_sniffer/blob_helper'
2
+ require 'language_sniffer/file_blob'
3
+ require 'language_sniffer/language'
4
+ require 'language_sniffer/pathname'
5
+
6
+ module LanguageSniffer
7
+ def self.detect(path, options={})
8
+ FileBlob.new(path, options[:pwd], options[:content])
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: language_sniffer
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - GitHub, Inc.
14
+ - Michael Grosser
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-09-17 00:00:00 +02:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :development
33
+ name: rake
34
+ version_requirements: *id001
35
+ prerelease: false
36
+ description:
37
+ email: grosser.michael@gmail.com
38
+ executables:
39
+ - language_sniffer
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - lib/language_sniffer.rb
46
+ - lib/language_sniffer/pathname.rb
47
+ - lib/language_sniffer/language.rb
48
+ - lib/language_sniffer/version.rb
49
+ - lib/language_sniffer/blob_helper.rb
50
+ - lib/language_sniffer/languages.yml
51
+ - lib/language_sniffer/file_blob.rb
52
+ - bin/language_sniffer
53
+ has_rdoc: true
54
+ homepage: http://github.com/grosser/language_sniffer
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options: []
59
+
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ hash: 3
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ requirements: []
81
+
82
+ rubyforge_project:
83
+ rubygems_version: 1.6.2
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Language detection
87
+ test_files: []
88
+