Class Wac::Pod

  1. lib/wac/pod.rb
Parent: Object

Methods

public class

  1. collection
  2. new

public instance

  1. img
  2. inspect
  3. markup
  4. plaintext
  5. structured?
  6. to_s
  7. types

Included modules

  1. XmlContainer
  2. Enumerable

Classes and Modules

Class Wac::Pod::State
Class Wac::Pod::Subpod

Attributes

query [R]
states [R]
subpods [R]

Public class methods

collection (xml, options = {})
[show source]
# File lib/wac/pod.rb, line 10
    def self.collection(xml, options = {})
      Nokogiri::XML(xml.to_s).search('pod').map {|p_xml| new(p_xml, options)}
    end
new (xml, options = {})
[show source]
# File lib/wac/pod.rb, line 14
    def initialize(xml, options = {})
      @query = options[:query]
      @xml = Nokogiri::XML(xml.to_s).search('pod').first
      @subpods = Subpod.collection(@xml.search('subpod'), options)
      @states = State.collection(@xml.search('states'), options)
      @xml or raise MissingNodeError, "<pod> node missing from xml: #{xml[0..20]}..."
      types.each {|type| extend type}
    end

Public instance methods

img ()
[show source]
# File lib/wac/pod.rb, line 39
    def img
      subpods.detect(&:img).try(:img)
    end
inspect ()
[show source]
# File lib/wac/pod.rb, line 27
    def inspect
      "#<#{scanner}: #{to_s}>"
    end
markup ()
[show source]
# File lib/wac/pod.rb, line 43
    def markup
      @markup ||= (xml.search('markup').text || '')
    end
plaintext ()
[show source]
# File lib/wac/pod.rb, line 35
    def plaintext
      subpods.detect(&:plaintext).try(:plaintext)
    end
structured? ()
[show source]
# File lib/wac/pod.rb, line 47
    def structured?
      subpods.any?
    end
to_s ()
[show source]
# File lib/wac/pod.rb, line 23
    def to_s
      "#{title}: #{structured? ? plaintext : "'#{markup[0..20]}...'"} #{states.join(", ") if states.any?}"
    end
types ()
[show source]
# File lib/wac/pod.rb, line 31
    def types
      @types ||= scanner.split(',').map {|type| Wac.mixin(Result, type)}
    end