Class: TagFormatter::Formatter
- Inherits:
-
Object
- Object
- TagFormatter::Formatter
- Defined in:
- lib/tag_formatter/formatter.rb
Constant Summary collapse
- @@_known_params =
[:tags, :tag_start, :tag_end, :inline_comment_delimiter, :block_comment_start, :block_comment_end]
Instance Attribute Summary collapse
-
#input ⇒ Object
Returns the value of attribute input.
Instance Method Summary collapse
-
#initialize(input, params = {}) ⇒ Formatter
constructor
Creates a new instance of TagFormatter::Formatter.
-
#parse ⇒ Object
Parses the supplied input and returned a decommented, tagified and cleaned string.
Constructor Details
#initialize(input, params = {}) ⇒ Formatter
Creates a new instance of TagFormatter::Formatter.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/tag_formatter/formatter.rb', line 21 def initialize input, params={} params = { tags: {}, tag_start: '{', tag_end: '}', inline_comment_delimiter: '#', block_comment_start: '/*', block_comment_end: '*/' }.merge(params) # Assigning input to @input if string @input = if input.is_a? String input # Reading input and assigning the resultant string to @input elsif input.is_a? File input.read.to_s # Raise a TypeError. else raise TypeError, "input was an `#{input.class.name}', expected a `String' or `File'." end # Assign the param values to the (known) attributes. @@_known_params.each do |attr| self.send(attr.to_s + "=", params[attr]) end end |
Instance Attribute Details
#input ⇒ Object
Returns the value of attribute input.
7 8 9 |
# File 'lib/tag_formatter/formatter.rb', line 7 def input @input end |
Instance Method Details
#parse ⇒ Object
Parses the supplied input and returned a decommented, tagified and cleaned string.
50 51 52 |
# File 'lib/tag_formatter/formatter.rb', line 50 def parse tagify(decommentify(@input)).strip end |