Class: Markabb::Tag
- Inherits:
-
Object
- Object
- Markabb::Tag
- Defined in:
- lib/markabb/classes/tag.rb
Overview
Used for all tags (passed to register_tag) Takes a REGEX matcher and a string to replace it with
Instance Attribute Summary collapse
-
#group ⇒ Object
Returns the value of attribute group.
-
#matcher ⇒ Object
readonly
Returns the value of attribute matcher.
-
#name ⇒ Object
Returns the value of attribute name.
-
#replace ⇒ Object
readonly
Returns the value of attribute replace.
Instance Method Summary collapse
-
#initialize(matcher, replace) ⇒ Tag
constructor
Creates the Markabb::Tag object.
-
#run(s, config) ⇒ Object
Runs the tag on the input string.
Constructor Details
#initialize(matcher, replace) ⇒ Tag
Creates the Markabb::Tag object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/markabb/classes/tag.rb', line 41 def initialize(matcher, replace) if matcher.is_a? String @matcher = generate_matcher(matcher) elsif matcher.is_a? Regexp @matcher = matcher else raise 'matcher is not valid' end if replace.is_a? String @replace = replace elsif replace.is_a? Markabb::Callback @replace = false @callback = replace else raise 'Replace is not valid' end end |
Instance Attribute Details
#group ⇒ Object
Returns the value of attribute group.
38 39 40 |
# File 'lib/markabb/classes/tag.rb', line 38 def group @group end |
#matcher ⇒ Object (readonly)
Returns the value of attribute matcher.
37 38 39 |
# File 'lib/markabb/classes/tag.rb', line 37 def matcher @matcher end |
#name ⇒ Object
Returns the value of attribute name.
38 39 40 |
# File 'lib/markabb/classes/tag.rb', line 38 def name @name end |
#replace ⇒ Object (readonly)
Returns the value of attribute replace.
37 38 39 |
# File 'lib/markabb/classes/tag.rb', line 37 def replace @replace end |
Instance Method Details
#run(s, config) ⇒ Object
Runs the tag on the input string
Takes the target string and a Markabb::Config object
62 63 64 65 66 67 68 |
# File 'lib/markabb/classes/tag.rb', line 62 def run(s, config) if @replace return s.gsub(@matcher, generate_replacement(@replace, config)) elsif @callback return run_callback(s) end end |