Class: Agio::Block
- Inherits:
-
Object
- Object
- Agio::Block
- Defined in:
- lib/agio/block.rb
Overview
A Block is the fundamental collection for the Broker that is used to then generate the Markdown.
Instance Attribute Summary collapse
-
#contents ⇒ Object
readonly
The contents of the Block.
-
#description ⇒ Object
readonly
The description of the HTML element the Block represents (this will always be a Nokogiri::HTML::ElementDescription or
nil). -
#name ⇒ Object
readonly
The name of the element the Block is for.
-
#options ⇒ Object
readonly
The options, if provided, for the element.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Used mostly for testing.
-
#append(*contents) ⇒ Object
Append the contents provided to the Block.
-
#block? ⇒ Boolean
Returns
trueif this Block is an HTML block element. -
#can_contain?(other) ⇒ Boolean
Returns
trueif this Block can contain the other Block provided. -
#definition? ⇒ Boolean
Returns
trueif the Block is a definition item (‘dt’ or ‘dd’). -
#dl? ⇒ Boolean
Returns
trueif the block is a definition list (‘dl’) element. -
#initialize(name, options = {}) ⇒ Block
constructor
Create the Block from a tag start.
-
#inline? ⇒ Boolean
Returns
trueif this Block is an HTML inline element. - #inspect ⇒ Object
-
#li? ⇒ Boolean
Returns
trueif the Block is a ‘li’ (list item) element. -
#pre? ⇒ Boolean
Returns
trueif the Block is a ‘pre’ element. -
#sibling_of?(other) ⇒ Boolean
Determine whether the
otherBlock is a sibling of this Block. -
#standard? ⇒ Boolean
Returns
trueif the Block is a standard HTML element (as understood by Nokogiri). -
#ul_ol? ⇒ Boolean
Returns
trueif the Block is a ‘ul’ or ‘ol’ element.
Constructor Details
#initialize(name, options = {}) ⇒ Block
Create the Block from a tag start.
31 32 33 34 35 |
# File 'lib/agio/block.rb', line 31 def initialize(name, = {}) @name, = name, @description = Agio::HTMLElementDescription[name] @contents = [] end |
Instance Attribute Details
#contents ⇒ Object (readonly)
The contents of the Block.
24 25 26 |
# File 'lib/agio/block.rb', line 24 def contents @contents end |
#description ⇒ Object (readonly)
The description of the HTML element the Block represents (this will always be a Nokogiri::HTML::ElementDescription or nil).
28 29 30 |
# File 'lib/agio/block.rb', line 28 def description @description end |
#name ⇒ Object (readonly)
The name of the element the Block is for.
18 19 20 |
# File 'lib/agio/block.rb', line 18 def name @name end |
#options ⇒ Object (readonly)
The options, if provided, for the element.
21 22 23 |
# File 'lib/agio/block.rb', line 21 def end |
Instance Method Details
#==(other) ⇒ Object
Used mostly for testing.
125 126 127 128 129 |
# File 'lib/agio/block.rb', line 125 def ==(other) name == other.name && == other. && contents == other.contents end |
#append(*contents) ⇒ Object
Append the contents provided to the Block.
38 39 40 |
# File 'lib/agio/block.rb', line 38 def append(*contents) @contents.push(*contents) end |
#block? ⇒ Boolean
Returns true if this Block is an HTML block element.
56 57 58 |
# File 'lib/agio/block.rb', line 56 def block? description && description.block? end |
#can_contain?(other) ⇒ Boolean
Returns true if this Block can contain the other Block provided.
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/agio/block.rb', line 62 def can_contain?(other) case other when Agio::Block description && description.sub_elements.include?(other.name) when String description && description.sub_elements.include?(other) else false end end |
#definition? ⇒ Boolean
Returns true if the Block is a definition item (‘dt’ or ‘dd’).
93 94 95 |
# File 'lib/agio/block.rb', line 93 def definition? name == "dt" or name == "dd" end |
#dl? ⇒ Boolean
Returns true if the block is a definition list (‘dl’) element.
99 100 101 |
# File 'lib/agio/block.rb', line 99 def dl? definition? or name == "dl" end |
#inline? ⇒ Boolean
Returns true if this Block is an HTML inline element.
50 51 52 |
# File 'lib/agio/block.rb', line 50 def inline? description && description.inline? end |
#inspect ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/agio/block.rb', line 9 def inspect if .empty? %Q(#<#{self.class} #{name} #{contents.inspect}>) else %Q(#<#{self.class} #{name}(#{options.inspect}) #{contents.inspect}>) end end |
#li? ⇒ Boolean
Returns true if the Block is a ‘li’ (list item) element.
75 76 77 |
# File 'lib/agio/block.rb', line 75 def li? name == "li" end |
#pre? ⇒ Boolean
Returns true if the Block is a ‘pre’ element.
81 82 83 |
# File 'lib/agio/block.rb', line 81 def pre? name == "pre" end |
#sibling_of?(other) ⇒ Boolean
Determine whether the other Block is a sibling of this Block. Blocks are siblings if:
-
This Block cannot contain the other Block.
-
This Block is a definition (‘dt’ or ‘dd’) and so is the other Block.
-
This Block’s name and the other Block’s name are the same.
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/agio/block.rb', line 111 def sibling_of?(other) if can_contain? other false elsif definition? and other.definition? true elsif name == other.name true else false end end |
#standard? ⇒ Boolean
Returns true if the Block is a standard HTML element (as understood by Nokogiri).
44 45 46 |
# File 'lib/agio/block.rb', line 44 def standard? !!description end |
#ul_ol? ⇒ Boolean
Returns true if the Block is a ‘ul’ or ‘ol’ element.
87 88 89 |
# File 'lib/agio/block.rb', line 87 def ul_ol? name == "ul" or name == "ol" end |