class CurseClient::Feed

Constants

COMPLETE_URL
DEFAULT_URL
HOURLY_URL

Attributes

url[R]

Public Class Methods

new(url = DEFAULT_URL) click to toggle source
# File lib/curse_client/feed.rb, line 12
def initialize(url = DEFAULT_URL)
  @url = url
end

Public Instance Methods

complete() click to toggle source
# File lib/curse_client/feed.rb, line 28
def complete
  download_bz2(COMPLETE_URL)
end
complete_timestamp() click to toggle source
# File lib/curse_client/feed.rb, line 24
def complete_timestamp
  get_timestamp(COMPLETE_URL)
end
hourly() click to toggle source
# File lib/curse_client/feed.rb, line 20
def hourly
  download_bz2(HOURLY_URL + "?t=#{hourly_timestamp}")
end
hourly_timestamp() click to toggle source
# File lib/curse_client/feed.rb, line 16
def hourly_timestamp
  get_timestamp(HOURLY_URL)
end

Private Instance Methods

download_bz2(url) click to toggle source
# File lib/curse_client/feed.rb, line 36
def download_bz2(url)
  open(COMPLETE_URL) do |request|
    Bzip2::FFI::Reader.open(request) do |bz2|
      fix_keys(JSON.parse(bz2.read))
    end
  end
end
fix_keys(value) click to toggle source
# File lib/curse_client/feed.rb, line 50
def fix_keys(value)
  case value
  when Array
    value.map{ |v| fix_keys(v) }
  when Hash
    Hash[value.map { |k, v| [underscore(k).to_sym, fix_keys(v)] }]
  else
    value
  end
end
get_timestamp(url) click to toggle source
# File lib/curse_client/feed.rb, line 44
def get_timestamp(url)
  open(url + ".txt") do |request|
    Integer(request.read)
  end
end
underscore(name) click to toggle source
# File lib/curse_client/feed.rb, line 61
def underscore(name)
  return name.downcase if name.match(/\A[A-Z]+\z/)
  name.
    gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
    gsub(/([a-z])([A-Z])/, '\1_\2').
    downcase
end