Class: Sparkleology::LatestVersionCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/sparkleology/latest_version_command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rss_feed_url) ⇒ LatestVersionCommand

Returns a new instance of LatestVersionCommand.



4
5
6
# File 'lib/sparkleology/latest_version_command.rb', line 4

def initialize(rss_feed_url)
  @rss_feed_url = rss_feed_url
end

Instance Attribute Details

#rss_feed_urlObject (readonly)

Returns the value of attribute rss_feed_url.



2
3
4
# File 'lib/sparkleology/latest_version_command.rb', line 2

def rss_feed_url
  @rss_feed_url
end

Instance Method Details

#fetch_feedObject



22
23
24
# File 'lib/sparkleology/latest_version_command.rb', line 22

def fetch_feed
  open(rss_feed_url).read
end

#fetch_feed_in_temp_fileObject



16
17
18
19
20
# File 'lib/sparkleology/latest_version_command.rb', line 16

def fetch_feed_in_temp_file
  File.open(tmp_file_path, "w+") do |file|
    file << self.fetch_feed
  end
end

#runObject



8
9
10
11
12
13
14
# File 'lib/sparkleology/latest_version_command.rb', line 8

def run
  fetch_feed_in_temp_file
  feed_xml = XML::Document.file(tmp_file_path)
  node = feed_xml.find_first "//rss/channel/item"
  node = node.find_first "enclosure"
  node["url"]
end

#tmp_file_pathObject



26
27
28
# File 'lib/sparkleology/latest_version_command.rb', line 26

def tmp_file_path
  File.join(Dir::tmpdir, "sparkleology.rss")
end