class ContributorsStats::Updater::Html
Update a target file with content
Constants
- DEFAULT_REPLACE
Default replace template
- DEFAULT_SEARCH
Default search pattern
Attributes
file_content[R]
replace[RW]
replace_content[R]
search[RW]
Public Class Methods
handles?(file)
click to toggle source
check if given file is supported by this updater
# File lib/plugins/contributors_stats/updater/html.rb, line 14 def self.handles?(file) %w{ .html .html.erb }.any?{|ext| file.end_with?(ext) } end
new(file_content, replace_content, options = {})
click to toggle source
set initial parameters, set default options
# File lib/plugins/contributors_stats/updater/html.rb, line 24 def initialize(file_content, replace_content, options = {}) @search = options[:search] || DEFAULT_SEARCH @replace = options[:replace] || DEFAULT_REPLACE @file_content = file_content @replace_content = replace_content end
update(file_content, replace_content, options = {})
click to toggle source
perform the content update
# File lib/plugins/contributors_stats/updater/html.rb, line 19 def self.update(file_content, replace_content, options = {}) new(file_content, replace_content, options).to_s end
Public Instance Methods
to_s()
click to toggle source
perform the replace operation
# File lib/plugins/contributors_stats/updater/html.rb, line 32 def to_s file_content.sub( search, eval(replace) ) end