Class: Howitzer::Meta::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/howitzer/meta/entry.rb

Overview

This class provides access to meta information entities

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Entry

Creates new meta entry instance for the page which provides access to elements, iframes and sections

Parameters:



9
10
11
# File 'lib/howitzer/meta/entry.rb', line 9

def initialize(context)
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



5
6
7
# File 'lib/howitzer/meta/entry.rb', line 5

def context
  @context
end

Instance Method Details

#element(name) ⇒ Meta::Element

Finds element by name

Parameters:

  • name (String, Symbol)

    element name

Returns:



25
26
27
# File 'lib/howitzer/meta/entry.rb', line 25

def element(name)
  elements.find { |el| el.name == name.to_s }
end

#elementsArray

Returns array of elements

Returns:

  • (Array)


15
16
17
18
19
20
# File 'lib/howitzer/meta/entry.rb', line 15

def elements
  @elements ||= context
                .private_methods
                .grep(/\A(?!wait_)\w+_element\z/)
                .map { |el| Meta::Element.new(el.to_s.gsub('_element', ''), context) }
end

#iframe(name) ⇒ Meta::Iframe

Finds iframe by name

Parameters:

  • name (String, Symbol)

    iframe name

Returns:



57
58
59
# File 'lib/howitzer/meta/entry.rb', line 57

def iframe(name)
  iframes.find { |el| el.name == name.to_s }
end

#iframesArray

Returns array of iframes

Returns:

  • (Array)


47
48
49
50
51
52
# File 'lib/howitzer/meta/entry.rb', line 47

def iframes
  @iframes ||= context
               .public_methods
               .grep(/\A(?!wait_)\w+_iframe$\z/)
               .map { |el| Meta::Iframe.new(el.to_s.gsub('_iframe', ''), context) }
end

#section(name) ⇒ Meta::Section

Finds section by name

Parameters:

  • name (String, Symbol)

    section name

Returns:



41
42
43
# File 'lib/howitzer/meta/entry.rb', line 41

def section(name)
  sections.find { |el| el.name == name.to_s }
end

#sectionsArray

Returns array of sections

Returns:

  • (Array)


31
32
33
34
35
36
# File 'lib/howitzer/meta/entry.rb', line 31

def sections
  @sections ||= context
                .public_methods
                .grep(/\A(?!wait_)\w+_section$\z/)
                .map { |el| Meta::Section.new(el.to_s.gsub('_section', ''), context) }
end