Class: OCLC::Classify::Response
- Inherits:
-
Object
- Object
- OCLC::Classify::Response
- Defined in:
- lib/oclc_classify.rb
Constant Summary collapse
- XPATH =
{ :code => '//response/@code', :author => '//work/@author', :title => '//work/@title', :recommendations => '//recommendations', }
- KEYS =
{ :popular => 'mostpopular', :recent => 'mostrecent', :latest => 'latestedition', }
Instance Attribute Summary collapse
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(url) ⇒ Response
constructor
A new instance of Response.
- #recommendations(scheme, key) ⇒ Object
Constructor Details
#initialize(url) ⇒ Response
Returns a new instance of Response.
95 96 97 98 99 100 |
# File 'lib/oclc_classify.rb', line 95 def initialize(url) @response = Nokogiri::HTML(open(url)) @code = @response.xpath(XPATH[:code]).to_s @author = @response.xpath(XPATH[:author]).to_s @title = @response.xpath(XPATH[:title]).to_s end |
Instance Attribute Details
#author ⇒ Object (readonly)
Returns the value of attribute author.
80 81 82 |
# File 'lib/oclc_classify.rb', line 80 def @author end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
80 81 82 |
# File 'lib/oclc_classify.rb', line 80 def code @code end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
80 81 82 |
# File 'lib/oclc_classify.rb', line 80 def response @response end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
80 81 82 |
# File 'lib/oclc_classify.rb', line 80 def title @title end |
Instance Method Details
#recommendations(scheme, key) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/oclc_classify.rb', line 102 def recommendations(scheme, key) raise "Invalid scheme: must be 'ddc' or 'lcc'" unless scheme =~ /(dd|lc)c/ raise "Invalid key: " + key.to_s unless KEYS.keys.include? key path = '/' + scheme + '/' + KEYS[key] if @code == '0' or @code == '2' results = OCLC::Classify::Recommendations.new(@response.xpath(XPATH[:recommendations] + path)) results.process return results.recommendations else return [] end end |