Class: Philologic::Client::Response
- Inherits:
-
Object
- Object
- Philologic::Client::Response
- Includes:
- Enumerable
- Defined in:
- lib/philologic-client/response.rb
Overview
Generic server response.
Extended by Philologic::Client::Bibliography, Philologic::Client::Collocation, Philologic::Client::Concordance, Philologic::Client::Document, Philologic::Cilent::Frequency and Philologic::Client::Occurrence
Direct Known Subclasses
Bibliography, Collocation, Concordance, Document, Frequency, Occurrence
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Get Philologic::Client or
nil
.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Returns value of attribute
key
ornil
. -
#each(&block) ⇒ Object
Yield successive property keys.
-
#initialize(document, client = nil) ⇒ Response
constructor
Initialize Philologic::Client::Response object.
-
#keys ⇒ Object
Array
of sorted property keys.
Constructor Details
#initialize(document, client = nil) ⇒ Response
Initialize Philologic::Client::Response object.
Params:
document
-
Nokogiri document
client
-
(optional) Philologic::Client object or
nil
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/philologic-client/response.rb', line 27 def initialize(document, client = nil) raise('nil document') if document.nil? @client = client @doc = document @properties = {} @doc.css('span.philologic_property').each do |p| @properties[ p.attributes['title'].value ] = p.children.text end end |
Instance Attribute Details
#client ⇒ Object (readonly)
Get Philologic::Client or nil
18 19 20 |
# File 'lib/philologic-client/response.rb', line 18 def client @client end |
Instance Method Details
#[](key) ⇒ Object
Returns value of attribute key
or nil
.
41 42 43 |
# File 'lib/philologic-client/response.rb', line 41 def [](key) @properties[key] end |
#each(&block) ⇒ Object
Yield successive property keys.
48 49 50 |
# File 'lib/philologic-client/response.rb', line 48 def each(&block) keys.each { |k| block.call(k) } end |
#keys ⇒ Object
Array
of sorted property keys.
55 56 57 |
# File 'lib/philologic-client/response.rb', line 55 def keys @properties.keys.sort end |