Class: Helpers::ContentList

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(items, indentation) ⇒ ContentList

Returns a new instance of ContentList.



84
85
86
87
# File 'lib/helpers.rb', line 84

def initialize(items, indentation)
  self.indentation = indentation
  self.push(*items)
end

Instance Attribute Details

#indentationObject

Returns the value of attribute indentation.



83
84
85
# File 'lib/helpers.rb', line 83

def indentation
  @indentation
end

Instance Method Details

#find_tag(&block) ⇒ Object



100
101
102
103
104
# File 'lib/helpers.rb', line 100

def find_tag(&block)
  self.find do |item|
    block.call(item) if item.respond_to?(:name)
  end
end

#inspectObject



112
113
114
# File 'lib/helpers.rb', line 112

def inspect
  self.to_s
end

#select_tags(&block) ⇒ Object



106
107
108
109
110
# File 'lib/helpers.rb', line 106

def select_tags(&block)
  self.select do |item|
    block.call(item) if item.respond_to?(:name)
  end
end

#to_sObject



89
90
91
92
93
94
95
96
97
98
# File 'lib/helpers.rb', line 89

def to_s
  self.map do |item|
    if item.respond_to?(:indentation)
      item.indentation = self.indentation
      item
    else
      "#{"  " * self.indentation}#{item}"
    end
  end.join("\n")
end