Class: ContributorsStats::Updater::Html
- Inherits:
-
Object
- Object
- ContributorsStats::Updater::Html
- Defined in:
- lib/plugins/contributors_stats/updater/html.rb
Overview
Update a target file with content
Constant Summary collapse
- DEFAULT_SEARCH =
Default search pattern
/<span class="contributors">.*?<\/span>/m
- DEFAULT_REPLACE =
Default replace template
%q{%Q{<span class="contributors">\n#{replace_content.join("\n")}\n</span>}}
Instance Attribute Summary collapse
-
#file_content ⇒ Object
readonly
Returns the value of attribute file_content.
-
#replace ⇒ Object
Returns the value of attribute replace.
-
#replace_content ⇒ Object
readonly
Returns the value of attribute replace_content.
-
#search ⇒ Object
Returns the value of attribute search.
Class Method Summary collapse
-
.handles?(file) ⇒ Boolean
check if given file is supported by this updater.
-
.update(file_content, replace_content, options = {}) ⇒ Object
perform the content update.
Instance Method Summary collapse
-
#initialize(file_content, replace_content, options = {}) ⇒ Html
constructor
set initial parameters, set default options.
-
#to_s ⇒ Object
perform the replace operation.
Constructor Details
#initialize(file_content, replace_content, options = {}) ⇒ Html
set initial parameters, set default options
24 25 26 27 28 29 |
# File 'lib/plugins/contributors_stats/updater/html.rb', line 24 def initialize(file_content, replace_content, = {}) @search = [:search] || DEFAULT_SEARCH @replace = [:replace] || DEFAULT_REPLACE @file_content = file_content @replace_content = replace_content end |
Instance Attribute Details
#file_content ⇒ Object (readonly)
Returns the value of attribute file_content.
11 12 13 |
# File 'lib/plugins/contributors_stats/updater/html.rb', line 11 def file_content @file_content end |
#replace ⇒ Object
Returns the value of attribute replace.
10 11 12 |
# File 'lib/plugins/contributors_stats/updater/html.rb', line 10 def replace @replace end |
#replace_content ⇒ Object (readonly)
Returns the value of attribute replace_content.
11 12 13 |
# File 'lib/plugins/contributors_stats/updater/html.rb', line 11 def replace_content @replace_content end |
#search ⇒ Object
Returns the value of attribute search.
10 11 12 |
# File 'lib/plugins/contributors_stats/updater/html.rb', line 10 def search @search end |
Class Method Details
.handles?(file) ⇒ Boolean
check if given file is supported by this updater
14 15 16 |
# 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 |
.update(file_content, replace_content, options = {}) ⇒ Object
perform the content update
19 20 21 |
# File 'lib/plugins/contributors_stats/updater/html.rb', line 19 def self.update(file_content, replace_content, = {}) new(file_content, replace_content, ).to_s end |
Instance Method Details
#to_s ⇒ Object
perform the replace operation
32 33 34 |
# File 'lib/plugins/contributors_stats/updater/html.rb', line 32 def to_s file_content.sub( search, eval(replace) ) end |