Class: SoloRails
- Inherits:
-
Object
- Object
- SoloRails
- Defined in:
- lib/solo-rails.rb
Class Method Summary collapse
- .published_years(record_type, limit = nil, q = nil) ⇒ Object
-
.search(*args) ⇒ Object
returns nested hash record for given search - PG 2011-01-21.
-
.show(id) ⇒ Object
returns SoloHash of values for individual catalogue record.
- .site=(site) ⇒ Object
Class Method Details
.published_years(record_type, limit = nil, q = nil) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/solo-rails.rb', line 136 def self.published_years(record_type, limit=nil, q=nil) q.nil? ? q = "Is Website Feature:Y" : q << ";Is Website Feature:Y" newest_record = IserSolo.new.search :q => q, :per_page => 1, :sort => "Publication Date:d", :select => "Publication Date", :ctrt => ":#{record_type}" d = newest_record.content_types.first.records.first.publication_date if (d.to_s =~ /(20|19)\d{2}/) != 0 newest_year = Chronic.parse("#{d}").year else newest_year = Chronic.parse("01 Jan #{d}").year end oldest_record = IserSolo.new.search :q => q, :per_page => 1, :sort => "Publication Date:a", :select => "Publication Date", :ctrt => ":#{record_type}" d = oldest_record.content_types.first.records.first.publication_date if (d.to_s =~ /(20|19)\d{2}/) != 0 oldest_year = Chronic.parse("#{d}").year else oldest_year = Chronic.parse("01 Jan #{d}").year end if limit.nil? newest_year.downto(oldest_year) else Range.new(oldest_year, newest_year).to_a.reverse[0..limit] end end |
.search(*args) ⇒ Object
returns nested hash record for given search - PG 2011-01-21
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/solo-rails.rb', line 56 def self.search(*args) = args.pop q, ctrt, select, sort, page, material, search_id, per_page, ignore_is_website_feature = () # If we have a value of search_id, then should only also pass: search_id, select, sort, page, per_page & material url = "#{@site}searchcatalogues?" query_string = [] if search_id.present? query_string << "searchid=#{search_id}" else query_string << "q=#{q}" query_string << "ctrt=#{ctrt}" if ctrt.present? end query_string << "page=#{page}" if page.present? query_string << "pageSize=#{per_page}" if per_page.present? query_string << "sort=#{sort}" if sort.present? query_string << "fields=#{select}" if select.present? query_string << "material=#{material}" if material.present? url += query_string.join("&") begin soutron_data = Nokogiri::XML(open(url, :read_timeout => 180)) rescue Exception => e # Rails.logger.info("SOLO Error in URL: " + url) end response = SoloHash.new Rails.logger.info("#{soutron_data.xpath("/soutron/search_info").attribute("id").text}") = {:id => soutron_data.xpath("/soutron/search_info").attribute("id").text} ["total_items".to_sym] = soutron_data.xpath("/soutron/search_info").attribute("totalItems").text ["page".to_sym] = page ["per_page".to_sym] = per_page ["select".to_sym] = select if soutron_data.xpath("count(//ct)") > 0 unless soutron_data.xpath("/soutron/search_info/catalogs_view/ct[*]").first.nil? ["active_content_type".to_sym] = soutron_data.xpath("/soutron/search_info/catalogs_view/ct[*]").first.attribute("name").text ["active_content_type_count".to_sym] = soutron_data.xpath("/soutron/search_info/catalogs_view/ct[*]").first.attribute("count").text end end response.merge!("search_info".to_sym => ) @content_types = [] soutron_data.xpath("/soutron/search_info/catalogs_view/ct").each do |ct| content_type = SoloHash.new content_type.merge!( { "content_type".to_sym => ct.attribute("name").text } ) content_type.merge!( { "content_type_display".to_sym => ct.attribute("caption").text } ) content_type.merge!( { "size".to_sym => ct.attribute("count").text } ) @records = [] ct.xpath("./ctlgs/cat").each do |cat| record = SoloHash.new record.merge!( {:id => cat.attribute("id").text, :record_type => cat.xpath("./rt").attribute("name").text} ) cat.xpath("./fs/f").each do |f| if f.xpath("count(./vs/v)") > 0 # only include field if it has a value record[uscore(f.attribute("name").text).to_sym] = parse_values(f.attribute("ft").text, f.xpath("./vs/v")) end # / if has value end # /f @records << record end # /cat content_type.merge!({"records".to_sym => @records }) @content_types << content_type end # /ct response.merge!(:content_types => @content_types) return response end |
.show(id) ⇒ Object
returns SoloHash of values for individual catalogue record
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/solo-rails.rb', line 19 def self.show(id) response = SoloHash.new url = "#{@site}getcatalogue?id=#{CGI.escape(id)}" begin soutron_data = Nokogiri::XML(open(url, :read_timeout => 180)) response[:id] = soutron_data.xpath("/soutron/catalogs_view/ct/cat").attribute("id").text # response[:request_url] = url - removed for security/speed purposes - PG 2011-02-17 response[:content_type] = soutron_data.xpath("/soutron/catalogs_view/ct").attribute("name").text response[:content_type_display] = soutron_data.xpath("/soutron/catalogs_view/ct").attribute("caption").text response[:record_type] = soutron_data.xpath("/soutron/catalogs_view/ct/cat/rt").attribute("name").text soutron_data.xpath("/soutron/catalogs_view/ct/cat/fs/f").each do |f| if f.xpath("count(./vs/v)") > 0 response[uscore(f.attribute("name").text).to_sym] = parse_values(f.attribute("ft").text, f.xpath("./vs/v")) end end # find related records - PG 2011-03-01 if soutron_data.xpath("count(/soutron/catalogs_view/ct/cat/related_catalogs)") > 0 @related_records = [] soutron_data.xpath("/soutron/catalogs_view/ct/cat/related_catalogs/ct").each do || rrct = .attribute("name").text .xpath('ctlgs/cat').each do |r| = SoloHash.new .merge!({ "content_type".to_sym => rrct, "cid".to_sym => r.attribute("id").text }) @related_records << end end response[:related_records] = @related_records end rescue raise "Record #{id} not found" end return response end |
.site=(site) ⇒ Object
12 13 14 |
# File 'lib/solo-rails.rb', line 12 def site=(site) @site = site end |