Class: RichUrls::El

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

Constant Summary collapse

MAX_TEXT_LENGTH =
1000

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag) ⇒ El

Returns a new instance of El.



7
8
9
10
11
# File 'lib/el.rb', line 7

def initialize(tag)
  @tag = tag
  @open = true
  @attributes = {}
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



5
6
7
# File 'lib/el.rb', line 5

def attributes
  @attributes
end

#openObject (readonly)

Returns the value of attribute open.



5
6
7
# File 'lib/el.rb', line 5

def open
  @open
end

#tagObject (readonly)

Returns the value of attribute tag.



5
6
7
# File 'lib/el.rb', line 5

def tag
  @tag
end

Instance Method Details

#add(key, value) ⇒ Object



13
14
15
16
17
# File 'lib/el.rb', line 13

def add(key, value)
  return if @attributes[key]

  @attributes[key] = value
end

#append_text(str) ⇒ Object



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

def append_text(str)
  @attributes[:text] ||= ''

  str = str.strip
  length = @attributes[:text].length

  if length <= MAX_TEXT_LENGTH
    end_slice = MAX_TEXT_LENGTH - length
    sliced = str[0...end_slice]

    @attributes[:text] << sliced + ' '
  end
end

#close!Object



37
38
39
# File 'lib/el.rb', line 37

def close!
  @open = false
end

#textObject



33
34
35
# File 'lib/el.rb', line 33

def text
  @attributes[:text]&.strip
end