Class: CssRewrite::Rewriter

Inherits:
Object
  • Object
show all
Defined in:
lib/css-rewrite/rewriter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_filter, &block) ⇒ Rewriter

Returns a new instance of Rewriter.



5
6
7
8
# File 'lib/css-rewrite/rewriter.rb', line 5

def initialize(file_filter, &block)
  @file_filter = file_filter
  @replacement_block = block
end

Instance Attribute Details

#file_filterObject (readonly)

Returns the value of attribute file_filter.



3
4
5
# File 'lib/css-rewrite/rewriter.rb', line 3

def file_filter
  @file_filter
end

#replacement_blockObject (readonly)

Returns the value of attribute replacement_block.



3
4
5
# File 'lib/css-rewrite/rewriter.rb', line 3

def replacement_block
  @replacement_block
end

Instance Method Details

#matches?(filename) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/css-rewrite/rewriter.rb', line 10

def matches?(filename)
  case file_filter
    when String
      file_filter == filename
    when Regexp
      !!(file_filter =~ filename)
    else
      if file_filter.respond_to?(:call)
        file_filter.call(filename)
      end
  end
end

#rewrite(url) ⇒ Object



23
24
25
# File 'lib/css-rewrite/rewriter.rb', line 23

def rewrite(url)
  replacement_block.call(url)
end