Class: Tattoo::Ink

Inherits:
Object
  • Object
show all
Defined in:
lib/tattoo/ink.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, regexp, opts = {}) ⇒ Ink

Returns a new instance of Ink.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/tattoo/ink.rb', line 9

def initialize(name, regexp, opts={})
  @name = name.to_sym
  @regexp = regexp

  options = opts.dup
  @prefix = options.delete(:prefix) || DEFAULT_MARK_IDENTIFIER
  @token = options.delete(:token) || DEFAULT_TOKEN
  @host = options.delete(:host) || DEFAULT_HOST
  @url = options.delete(:url).to_s
  @attributes = options
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/tattoo/ink.rb', line 7

def name
  @name
end

Instance Method Details

#find_markings(text) ⇒ Object



25
26
27
# File 'lib/tattoo/ink.rb', line 25

def find_markings(text)
  text.scan(/#{prefix_regexp}#{@regexp}/).flatten
end

#mark(marking, text) ⇒ Object



21
22
23
# File 'lib/tattoo/ink.rb', line 21

def mark(marking, text)
  text.gsub(/#{@prefix}#{marking}/, link_tag_for(marking))
end