Class: LetsShopMapper::Model::OpenSearch::Feed

Inherits:
Object
  • Object
show all
Defined in:
lib/letsshop_mapper/model/opensearch/feed.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str = nil) ⇒ Feed

Returns a new instance of Feed.



15
16
17
18
19
20
# File 'lib/letsshop_mapper/model/opensearch/feed.rb', line 15

def initialize(str = nil)
  @title, @link, @encoding = nil
  @entries = []
  @facets = []
  parse(str) if str
end

Instance Attribute Details

#encodingObject (readonly)

Returns the value of attribute encoding.



13
14
15
# File 'lib/letsshop_mapper/model/opensearch/feed.rb', line 13

def encoding
  @encoding
end

#entriesObject (readonly)

Returns the value of attribute entries.



7
8
9
# File 'lib/letsshop_mapper/model/opensearch/feed.rb', line 7

def entries
  @entries
end

#facetsObject (readonly)

Returns the value of attribute facets.



11
12
13
# File 'lib/letsshop_mapper/model/opensearch/feed.rb', line 11

def facets
  @facets
end

#itemsperpageObject (readonly)

Returns the value of attribute itemsperpage.



9
10
11
# File 'lib/letsshop_mapper/model/opensearch/feed.rb', line 9

def itemsperpage
  @itemsperpage
end

Returns the value of attribute link.



6
7
8
# File 'lib/letsshop_mapper/model/opensearch/feed.rb', line 6

def link
  @link
end

#startindexObject (readonly)

Returns the value of attribute startindex.



8
9
10
# File 'lib/letsshop_mapper/model/opensearch/feed.rb', line 8

def startindex
  @startindex
end

#titleObject (readonly)

Returns the value of attribute title.



5
6
7
# File 'lib/letsshop_mapper/model/opensearch/feed.rb', line 5

def title
  @title
end

#totalresultsObject (readonly)

Returns the value of attribute totalresults.



10
11
12
# File 'lib/letsshop_mapper/model/opensearch/feed.rb', line 10

def totalresults
  @totalresults
end

#xmlObject (readonly)

Returns the value of attribute xml.



12
13
14
# File 'lib/letsshop_mapper/model/opensearch/feed.rb', line 12

def xml
  @xml
end

Instance Method Details

#get_facets_by(scope) ⇒ Object



44
45
46
47
48
# File 'lib/letsshop_mapper/model/opensearch/feed.rb', line 44

def get_facets_by(scope)
  results = []
  @facets.each { |f| if f.type == scope then results << f end }
  return results
end

#parse(str) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/letsshop_mapper/model/opensearch/feed.rb', line 22

def parse(str)
  @xml = Nokogiri::XML(str)
  @encoding = @xml.encoding
  if @xml.at('/xmlns:feed')
    @title = @xml.at('/xmlns:feed/xmlns:title').text
    @link = @xml.at('/xmlns:feed/xmlns:link')['href']
    @startindex =  @xml.at('/xmlns:feed/xmlns:startIndex').text
    @itemsperpage =  @xml.at('/xmlns:feed/xmlns:itemsPerPage').text
    @totalresults =  @xml.at('/xmlns:feed/xmlns:totalResults').text
    # Facets
    @xml.xpath('/xmlns:feed/xmlns:Query[@role="subset"]').each do |f|
       @facets << Base::Facet::new(f)
    end
    # Entries
    @xml.xpath('/xmlns:feed/xmlns:entry').each do |e|
       @entries << Entry::new(e)
    end
  else
    raise LetsShopMapper::Error::UnknownFeedTypeException::new
  end
end

#to_s(localtime = true) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/letsshop_mapper/model/opensearch/feed.rb', line 50

def to_s(localtime = true)
  s  = ''
  s += "Encoding: #{@encoding}\n"
  s += "Title: #{@title}\n"
  s += "Link: #{@link}\n"
  s += "Entries:\n"
  @entries.each { |i| s += i.to_s(localtime) }
  s += "Facets\n"
  @facets.each { |i| s += i.to_s(localtime) }
  s += "\n"
end