Class: TagAlong

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

Defined Under Namespace

Classes: Offsets

Constant Summary collapse

VERSION =
'0.6.1'

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
# File 'lib/tag_along.rb', line 21

def tag(open_tag, close_tag)
  @tagged_text = @split_text.inject([]) do |res, t|
    if t[:tagged]
      [open_tag, t[:text], close_tag].each { |text| res << text }
    else
      res << t[:text]
    end
    res
  end.join('')
end