Class: Philologic::Client::Response

Inherits:
Object
  • Object
show all
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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#clientObject (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

#keysObject

Array of sorted property keys.



55
56
57
# File 'lib/philologic-client/response.rb', line 55

def keys
  @properties.keys.sort
end