Skip to content

Instantly share code, notes, and snippets.

@Janther
Last active December 13, 2015 18:08
Show Gist options
  • Save Janther/4952754 to your computer and use it in GitHub Desktop.
Save Janther/4952754 to your computer and use it in GitHub Desktop.
Función para acceder al valor de la UF de cualquier fecha.
require 'nokogiri'
require 'open-uri'
def uf date = nil
date ||= Date.today
year = date.year
month = date.month
day = date.mday
sii_uf = "http://www.sii.cl/pagina/valores/uf/uf#{year}.htm"
uf_table = Nokogiri::HTML open(sii_uf)
uf = uf_table.css("table tbody tr")[day-1].css("td")[month-1].text.gsub(".", "").gsub(",", ".").to_f
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment