Class: WolframAlpha::Response

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
library/wolfram-alpha/response.rb

Overview

This is a response object that wraps the response data in a easily managable object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ Response

Construct a new response for a document.



11
12
13
# File 'library/wolfram-alpha/response.rb', line 11

def initialize document
  @pods = document.css("pod").map { |element| Pod.new element }
end

Instance Attribute Details

#podsObject (readonly)

Returns the value of attribute pods.



8
9
10
# File 'library/wolfram-alpha/response.rb', line 8

def pods
  @pods
end

Instance Method Details

#[](id) ⇒ Object

Return the first occurence of a pod with the id of id.



16
17
18
# File 'library/wolfram-alpha/response.rb', line 16

def [] id
  find { |pod| pod.id == id }
end

#eachObject

Calls the given block once for each element in self, passing that element as a parameter.

An Enumerator is returned if no block is given.



23
24
25
26
27
28
29
# File 'library/wolfram-alpha/response.rb', line 23

def each
  return @pods.to_enum unless block_given?

  @pods.each do |pod|
    yield pod
  end
end