Class: TagAlong

Inherits:
Object
  • Object
show all
Defined in:
lib/tag_along.rb,
lib/tag_along/offsets.rb,
lib/tag_along/version.rb,
lib/tag_along/tagged_text.rb

Defined Under Namespace

Classes: Offsets, TaggedText

Constant Summary collapse

VERSION =
'0.8.3'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, offsets) ⇒ TagAlong

Returns a new instance of TagAlong.



13
14
15
16
17
18
19
# File 'lib/tag_along.rb', line 13

def initialize(text, offsets)
  @offsets = offsets.is_a?(Offsets) ? offsets : Offsets.new(offsets)
  @text = text
  @split_text = nil
  @tagged_text = nil
  split_text
end

Instance Attribute Details

#textObject (readonly)

Returns the value of attribute text.



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

def text
  @text
end

Class Method Details

.versionObject



9
10
11
# File 'lib/tag_along.rb', line 9

def self.version
  VERSION
end

Instance Method Details

#tag(open_tag, close_tag) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/tag_along.rb', line 21

def tag(open_tag, close_tag)
  opts = {
    open_tag: open_tag,
    close_tag: close_tag,
    open_tag_subs: open_tag.scan(/%s/).size,
    close_tag_subs: close_tag.scan(/%s/).size,
  }
  @tagged_text = @split_text.inject([]) do |res, t|
    process_tag(res, t, opts)
    res
  end.join('')
end