Class: CopyrightHeader::Syntax

Inherits:
Object
  • Object
show all
Defined in:
lib/copyright_header/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, guess_extension = false) ⇒ Syntax

Returns a new instance of Syntax.



140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/copyright_header/parser.rb', line 140

def initialize(config, guess_extension = false)
  @guess_extension = guess_extension
  @config = {}
  syntax = YAML.load_file(config)
  syntax.each_value do |format|
    format['ext'].each do |ext|
      @config[ext] = {
        :before => format['before'],
        :after => format['after'],
        :comment => format['comment']
      }
    end
  end
end

Instance Attribute Details

#guess_extensionObject

Returns the value of attribute guess_extension.



138
139
140
# File 'lib/copyright_header/parser.rb', line 138

def guess_extension
  @guess_extension
end

Instance Method Details

#ext(file) ⇒ Object



155
156
157
158
159
160
161
# File 'lib/copyright_header/parser.rb', line 155

def ext(file)
  extension = File.extname(file)
  if @guess_extension && (extension.nil? || extension.empty?)
    extension = Linguist::FileBlob.new(file).language.primary_extension 
  end
  return extension
end

#header(file) ⇒ Object



167
168
169
# File 'lib/copyright_header/parser.rb', line 167

def header(file)
  Header.new(file, @config[ext(file)])
end

#supported?(file) ⇒ Boolean

Returns:

  • (Boolean)


163
164
165
# File 'lib/copyright_header/parser.rb', line 163

def supported?(file)
  @config.has_key? ext(file)
end