Class: Safran::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/safran/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



9
10
11
# File 'lib/safran/parser.rb', line 9

def initialize
  @url = 'http://www.safran.io/feed.rss'
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'lib/safran/parser.rb', line 7

def url
  @url
end

Instance Method Details

#parseObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/safran/parser.rb', line 13

def parse
  begin
    open(@url) do |rss|
      feed = RSS::Parser.parse(rss)
      feed.items.each do |item|
        print item
      end
    end
  rescue => e
    "Bir hata oluştu: #{e}"
  end
end


26
27
28
29
30
# File 'lib/safran/parser.rb', line 26

def print(item)
  puts "#{item.title}".colorize(:red)
  puts "#{item.link}".colorize(:blue).underline
  puts ''
end