Class: JMAFeed::Result
- Inherits:
-
Object
- Object
- JMAFeed::Result
- Defined in:
- lib/jma_feed/result.rb
Instance Attribute Summary collapse
-
#http_result ⇒ Object
readonly
Returns the value of attribute http_result.
Instance Method Summary collapse
- #body ⇒ Object
- #code ⇒ Object
- #doc ⇒ Object
- #entries ⇒ Object
- #id ⇒ Object
-
#initialize(http_result) ⇒ Result
constructor
A new instance of Result.
- #last_modified ⇒ Object
- #namespace ⇒ Object
- #related ⇒ Object
- #subtitle ⇒ Object
- #text(name) ⇒ Object
- #title ⇒ Object
- #updated ⇒ Object
Constructor Details
#initialize(http_result) ⇒ Result
Returns a new instance of Result.
4 5 6 |
# File 'lib/jma_feed/result.rb', line 4 def initialize(http_result) @http_result = http_result end |
Instance Attribute Details
#http_result ⇒ Object (readonly)
Returns the value of attribute http_result.
2 3 4 |
# File 'lib/jma_feed/result.rb', line 2 def http_result @http_result end |
Instance Method Details
#body ⇒ Object
12 13 14 |
# File 'lib/jma_feed/result.rb', line 12 def body http_result.body end |
#code ⇒ Object
8 9 10 |
# File 'lib/jma_feed/result.rb', line 8 def code http_result.code end |
#doc ⇒ Object
20 21 22 |
# File 'lib/jma_feed/result.rb', line 20 def doc @doc ||= Nokogiri::XML(body) end |
#entries ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/jma_feed/result.rb', line 52 def entries @entries ||= doc.xpath('/atom:feed/atom:entry', namespace).map do |entry| JMAFeed::ResultEntry.new( title: entry.xpath('atom:title', namespace).text, link: entry.xpath('atom:link/@href', namespace).text, id: entry.xpath('atom:id', namespace).text, updated: entry.xpath('atom:updated', namespace).text, author: entry.xpath('atom:author/atom:name', namespace).text, content: entry.xpath('atom:content', namespace).text, ) end end |
#id ⇒ Object
40 41 42 |
# File 'lib/jma_feed/result.rb', line 40 def id text('id') end |
#last_modified ⇒ Object
16 17 18 |
# File 'lib/jma_feed/result.rb', line 16 def last_modified DateTime.parse(http_result["Last-Modified"]) end |
#namespace ⇒ Object
24 25 26 |
# File 'lib/jma_feed/result.rb', line 24 def namespace {atom: doc.root.namespace.href} end |
#related ⇒ Object
48 49 50 |
# File 'lib/jma_feed/result.rb', line 48 def text('link[@rel="related"]/@href') end |
#subtitle ⇒ Object
36 37 38 |
# File 'lib/jma_feed/result.rb', line 36 def subtitle text('subtitle') end |
#text(name) ⇒ Object
28 29 30 |
# File 'lib/jma_feed/result.rb', line 28 def text(name) doc.xpath("/atom:feed/atom:#{name}", namespace).text end |
#title ⇒ Object
32 33 34 |
# File 'lib/jma_feed/result.rb', line 32 def title text('title') end |
#updated ⇒ Object
44 45 46 |
# File 'lib/jma_feed/result.rb', line 44 def updated DateTime.parse(text('updated')) end |