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.



137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/copyright_header/parser.rb', line 137

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.



135
136
137
# File 'lib/copyright_header/parser.rb', line 135

def guess_extension
  @guess_extension
end

Instance Method Details

#ext(file) ⇒ Object



152
153
154
155
156
157
158
# File 'lib/copyright_header/parser.rb', line 152

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



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

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

#supported?(file) ⇒ Boolean

Returns:

  • (Boolean)


160
161
162
# File 'lib/copyright_header/parser.rb', line 160

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