Class: RichUrls::El
- Inherits:
-
Object
- Object
- RichUrls::El
- Defined in:
- lib/el.rb
Constant Summary collapse
- MAX_TEXT_LENGTH =
1000
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#open ⇒ Object
readonly
Returns the value of attribute open.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
Instance Method Summary collapse
- #add(key, value) ⇒ Object
- #append_text(str) ⇒ Object
- #close! ⇒ Object
-
#initialize(tag) ⇒ El
constructor
A new instance of El.
- #text ⇒ Object
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
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/el.rb', line 5 def attributes @attributes end |
#open ⇒ Object (readonly)
Returns the value of attribute open.
5 6 7 |
# File 'lib/el.rb', line 5 def open @open end |
#tag ⇒ Object (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 |
#text ⇒ Object
33 34 35 |
# File 'lib/el.rb', line 33 def text @attributes[:text]&.strip end |