class TheCountryIdentity::RDF

Attributes

cache[RW]
country_name[R]
repository[R]
url[R]

Public Class Methods

new(country_name) click to toggle source
# File lib/the_country_identity/rdf.rb, line 14
def initialize(country_name)
  @cache = {}
  @country_name = country_name.downcase.gsub(' ', '_').gsub('usa', 'united_states')
  @url = @@URI_PREFIX + @country_name
end

Public Instance Methods

get_property(property_name) click to toggle source
# File lib/the_country_identity/rdf.rb, line 20
def get_property(property_name)
  return @cache[property_name] if @cache[property_name]

  begin
    unless repo.nil?
      options = { :predicate => ::RDF::URI("#{@@STATEMENT_PREFIX}#{property_name}") }
      repo.query(options) do |stmnt|
        @cache[property_name] = stmnt.object.value
      end
    end
  rescue => e
    puts "Not able to get country information, through exception: #{e}"
  end

  @cache[property_name]
end

Private Instance Methods

repo() click to toggle source
# File lib/the_country_identity/rdf.rb, line 39
def repo
  @repository ||= ::RDF::Repository.load(@url)
end