Class: Code2rubylearning::Filter
- Inherits:
-
Object
- Object
- Code2rubylearning::Filter
- Defined in:
- lib/code2rubylearning/filter.rb
Instance Method Summary collapse
- #apply ⇒ Object
- #convert(source) ⇒ Object
- #footer ⇒ Object
- #header(file_name) ⇒ Object
-
#initialize(current_file, options) ⇒ Filter
constructor
A new instance of Filter.
Constructor Details
#initialize(current_file, options) ⇒ Filter
Returns a new instance of Filter.
3 4 5 6 7 8 9 |
# File 'lib/code2rubylearning/filter.rb', line 3 def initialize current_file, @current_file = current_file @name = current_file.name @data = current_file.data @type = current_file.type @options = end |
Instance Method Details
#apply ⇒ Object
11 12 13 |
# File 'lib/code2rubylearning/filter.rb', line 11 def apply header(@name) << convert(@data) << end |
#convert(source) ⇒ Object
37 38 39 40 41 |
# File 'lib/code2rubylearning/filter.rb', line 37 def convert source source = source.gsub('<', '<') source = source.gsub('>', '>') source = source.gsub('Person', 'People') end |
#footer ⇒ Object
33 34 35 |
# File 'lib/code2rubylearning/filter.rb', line 33 def "[/code]\n" end |
#header(file_name) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/code2rubylearning/filter.rb', line 15 def header file_name header = "[code #{ @type }#{@options[:linenumbers] ? ' linenumbers' : ''}]\n" if @options[:filenames] data_lines = @data.split("\n") if data_lines.first.include? "#!" bin_line = data_lines.first + "\n" header << bin_line @data = @data.gsub(bin_line, "") end header << "#filename: #{ file_name }\n" end header end |