Class: Markabb::Tag

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#groupObject

Returns the value of attribute group.



38
39
40
# File 'lib/markabb/classes/tag.rb', line 38

def group
  @group
end

#matcherObject (readonly)

Returns the value of attribute matcher.



37
38
39
# File 'lib/markabb/classes/tag.rb', line 37

def matcher
  @matcher
end

#nameObject

Returns the value of attribute name.



38
39
40
# File 'lib/markabb/classes/tag.rb', line 38

def name
  @name
end

#replaceObject (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