class BoardGameGem::BGGBase

Protected Instance Methods

api_key_value() click to toggle source
# File lib/bgg_base.rb, line 61
def api_key_value
        key_for_api(nil, "value")
end
get_boolean(xml, path, key = nil) click to toggle source
# File lib/bgg_base.rb, line 29
def get_boolean(xml, path, key = nil)
        return get_integer(xml, path, key) == 1 rescue nil
end
get_datetime(xml, path, key) click to toggle source
# File lib/bgg_base.rb, line 53
def get_datetime(xml, path, key)
        return DateTime.strptime(get_string(xml, path, key), '%F %T')
end
get_float(xml, path, key = nil) click to toggle source
# File lib/bgg_base.rb, line 49
def get_float(xml, path, key = nil)
        return get_value(xml, path, key).to_f rescue nil
end
get_integer(xml, path, key = nil) click to toggle source
# File lib/bgg_base.rb, line 33
def get_integer(xml, path, key = nil)
        return get_value(xml, path, key).to_i rescue nil
end
get_integers(xml, path, key = nil) click to toggle source
# File lib/bgg_base.rb, line 37
def get_integers(xml, path, key = nil)
        return get_values(xml, path, key).map {|x| x.to_i } rescue nil
end
get_string(xml, path, key = nil) click to toggle source
# File lib/bgg_base.rb, line 41
def get_string(xml, path, key = nil)
        return get_value(xml, path, key).to_s rescue nil
end
get_strings(xml, path, key = nil) click to toggle source
# File lib/bgg_base.rb, line 45
def get_strings(xml, path, key = nil)
        return get_values(xml, path, key).map {|x| x.to_s } rescue nil
end
get_value(xml, path, key = nil) click to toggle source
# File lib/bgg_base.rb, line 5
def get_value(xml, path, key = nil)
        item = xml.at_css(path)
        if item.nil?
                return nil
        end
        if key.nil?
                return item.content
        else
                return item[key]
        end
end
get_values(xml, path, key = nil) click to toggle source
# File lib/bgg_base.rb, line 17
def get_values(xml, path, key = nil)
        results = []
        xml.css(path).each do |item|
                if key.nil?
                        results.push(item.content)
                else
                        results.push(item[key])
                end
        end
        return results
end
key_for_api(api1, api2) click to toggle source
# File lib/bgg_base.rb, line 57
def key_for_api(api1, api2)
        @api == 2 ? api2 : api1
end