Class: SodaXmlTeam::News

Inherits:
Object
  • Object
show all
Defined in:
lib/soda_xml_team/news.rb

Class Method Summary collapse

Class Method Details

.parse_news(document = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/soda_xml_team/news.rb', line 7

def self.parse_news(document={})

  output = []

  unless document.is_a? Nokogiri::XML::Document
    raise "Invalid XML news."
  end

  output = {}

  # Article meta data
  document.css('sports-content').each do ||
    output[:title] = .css('sports-title').first.content
    if !.css('byline person').empty?
      output[:author] = .css('byline person').first.content
    end
    output[:author_title] = .css('byline byttl').first.content
    output[:headline] = .css('article hedline hl1').first.content
    output[:abstract] = .css('article abstract').first.content.gsub(/\n/, "").strip
  end

  # Article content
  document.xpath('/xts:sports-content-set/sports-content/article/nitf/body/body.content').each do |article_body|
    output[:body] = article_body.css('*').to_s.gsub(/\n/, "").strip
  end

  return output

end