Class: NbpExchange::CurrencyXml
- Inherits:
-
Object
- Object
- NbpExchange::CurrencyXml
- Defined in:
- lib/nbp_exchange/currency_xml.rb
Constant Summary collapse
- DIR_URL =
"http://nbp.pl/kursy/xml/dir.txt"
- XML_URL =
"http://rss.nbp.pl/kursy/xml2/%{year}/a/%{xml_name}"
Instance Attribute Summary collapse
-
#date ⇒ Object
Returns the value of attribute date.
Instance Method Summary collapse
-
#initialize(date) ⇒ CurrencyXml
constructor
A new instance of CurrencyXml.
- #open_xml ⇒ Object
- #xml_name ⇒ Object
- #xml_names_list ⇒ Object
- #xml_url ⇒ Object
Constructor Details
#initialize(date) ⇒ CurrencyXml
Returns a new instance of CurrencyXml.
8 9 10 |
# File 'lib/nbp_exchange/currency_xml.rb', line 8 def initialize(date) @date = date end |
Instance Attribute Details
#date ⇒ Object
Returns the value of attribute date.
7 8 9 |
# File 'lib/nbp_exchange/currency_xml.rb', line 7 def date @date end |
Instance Method Details
#open_xml ⇒ Object
12 13 14 |
# File 'lib/nbp_exchange/currency_xml.rb', line 12 def open_xml open(xml_url).read end |
#xml_name ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/nbp_exchange/currency_xml.rb', line 16 def xml_name item = nil xml_names_list.each_line do |line| if line.match /a([0-9]+)z#{@date.strftime '%y%m%d'}/ item = line end end raise NoXMLForThisDate unless item @date.strftime '%y' + item[0, 4] + '.xml' end |
#xml_names_list ⇒ Object
28 29 30 |
# File 'lib/nbp_exchange/currency_xml.rb', line 28 def xml_names_list @xml_names_list ||= open(DIR_URL).read end |
#xml_url ⇒ Object
32 33 34 |
# File 'lib/nbp_exchange/currency_xml.rb', line 32 def xml_url XML_URL % {:year => @date.year, :xml_name => xml_name} end |