Module: LLT::Core::Containable
- Includes:
- Enumerable
- Defined in:
- lib/llt/core/containable.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#container ⇒ Object
readonly
Returns the value of attribute container.
-
#id ⇒ Object
(also: #n)
readonly
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(obj) ⇒ Object
- #[](arg) ⇒ Object
- #all?(&blk) ⇒ Boolean
- #as_json ⇒ Object
- #as_xml ⇒ Object
- #each(&blk) ⇒ Object
- #empty? ⇒ Boolean
- #include?(x) ⇒ Boolean
- #initialize(string, id = nil) ⇒ Object
- #to_s ⇒ Object
- #to_xml(tags = nil, indexing: true, recursive: true, inline: false, id_as: 'n', attrs: {}) ⇒ Object
-
#xml_tag ⇒ string
(also: #default_xml_tag)
The default xml tag defined for the instances class.
Instance Attribute Details
#container ⇒ Object (readonly)
Returns the value of attribute container.
6 7 8 |
# File 'lib/llt/core/containable.rb', line 6 def container @container end |
#id ⇒ Object (readonly) Also known as: n
Returns the value of attribute id.
6 7 8 |
# File 'lib/llt/core/containable.rb', line 6 def id @id end |
Class Method Details
.included(klass) ⇒ Object
85 86 87 |
# File 'lib/llt/core/containable.rb', line 85 def self.included(klass) klass.extend(ClassMethods) end |
Instance Method Details
#<<(obj) ⇒ Object
15 16 17 18 |
# File 'lib/llt/core/containable.rb', line 15 def <<(obj) @container << obj @container.flatten! end |
#[](arg) ⇒ Object
20 21 22 |
# File 'lib/llt/core/containable.rb', line 20 def [](arg) @container[arg] end |
#all?(&blk) ⇒ Boolean
73 74 75 |
# File 'lib/llt/core/containable.rb', line 73 def all?(&blk) @container.empty? ? false : super end |
#as_json ⇒ Object
59 60 61 |
# File 'lib/llt/core/containable.rb', line 59 def as_json @string end |
#as_xml ⇒ Object
55 56 57 |
# File 'lib/llt/core/containable.rb', line 55 def as_xml @string end |
#each(&blk) ⇒ Object
69 70 71 |
# File 'lib/llt/core/containable.rb', line 69 def each(&blk) @container.each(&blk) end |
#empty? ⇒ Boolean
81 82 83 |
# File 'lib/llt/core/containable.rb', line 81 def empty? @container.empty? end |
#include?(x) ⇒ Boolean
77 78 79 |
# File 'lib/llt/core/containable.rb', line 77 def include? x @container.include? x end |
#initialize(string, id = nil) ⇒ Object
9 10 11 12 13 |
# File 'lib/llt/core/containable.rb', line 9 def initialize(string, id = nil) @string = string @container = [] @id = id end |
#to_s ⇒ Object
24 25 26 |
# File 'lib/llt/core/containable.rb', line 24 def to_s @string end |
#to_xml(tags = nil, indexing: true, recursive: true, inline: false, id_as: 'n', attrs: {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/llt/core/containable.rb', line 28 def to_xml( = nil, indexing: true, recursive: true, inline: false, id_as: 'n', attrs: {}) # for easier recursion it's solved in a way that might # look awkward on first sight = Array() tag = .shift || default_xml_tag end_of_recursion = false val = if recursive && all? { |e| e.respond_to?(:to_xml)} attrs.merge!(inline_id(tag, id_as)) if inline && indexing recursive_xml(, indexing, inline, id_as, attrs) else end_of_recursion = true as_xml end if inline end_of_recursion ? wrap_with_xml(tag, val, indexing, id_as, attrs) : val else wrap_with_xml(tag, val, indexing, id_as, attrs) end end |
#xml_tag ⇒ string Also known as: default_xml_tag
Returns the default xml tag defined for the instances class.
64 65 66 |
# File 'lib/llt/core/containable.rb', line 64 def xml_tag self.class.default_xml_tag end |