class Abrupt::Converter

Converter

Attributes

format[RW]
hsh[RW]
result[RW]
uri[RW]
values[RW]

Public Class Methods

json(hsh) click to toggle source
# File lib/abrupt/converter.rb, line 61
def self.json(hsh)
  hsh.to_json
end
xml(hsh) click to toggle source
# File lib/abrupt/converter.rb, line 57
def self.xml(hsh)
  Gyoku.xml hsh
end

Public Instance Methods

add_to_result(statements) click to toggle source
# File lib/abrupt/converter.rb, line 65
def add_to_result(statements)
  statements.each { |stmt| @result << stmt }
end
append_pages_for_visitor(visitor) click to toggle source
# File lib/abrupt/converter.rb, line 107
def append_pages_for_visitor(visitor)
  pages = visitor.values[:pages][:page].ensure_to_a
  pages.each do |page|
    time = ::Abrupt.format_time(page[:entertime])
    Transformation::Client::Base.subclasses.each do |transformer_class|
      transformer = transformer_class.new(visitor.parent_uri + visitor.uri,
                                          ['Visit', time], page)
      add_to_result transformer.add_individuals
    end
  end
end
append_rules() click to toggle source
# File lib/abrupt/converter.rb, line 119
def append_rules
  Dir.glob(RULES_DIR).each do |rule_directory|
    Dir.glob(File.join(rule_directory, '*')).each do |rule_file|
      rule = Repository.load(rule_file)
      add_to_result(rule.statements)
    end
  end
end
append_tbox() click to toggle source
# File lib/abrupt/converter.rb, line 28
def append_tbox
  @result << Repository.load(VOC_FILE)
end
append_user_data(file) click to toggle source
# File lib/abrupt/converter.rb, line 93
def append_user_data(file)
  return unless file.is_a?(String) && File.exist?(file)
  xml = Hash.from_xml(File.read(file)).deep_symbolize_keys
  xml[:database][:visitor].ensure_to_a.each do |values|
    ip = values[:ip]
    next unless ip
    visitor = Transformation::Client::Visitor.new(['Website', @uri.to_s],
                                                  ['Visitor', ip], values)
    add_to_result visitor.add_individuals
    append_pages_for_visitor(visitor)
  end
  @result
end
append_website_data(hsh) click to toggle source
# File lib/abrupt/converter.rb, line 32
def append_website_data(hsh)
  init_hsh(hsh)
  @uri = URI(@hsh[:website][:domain])
  init_website
  perform
end
init(options = {}) click to toggle source
# File lib/abrupt/converter.rb, line 23
def init(options = {})
  @format = options[:format].try(:to_sym) || :turtle
  @result = Repository.new
end
init_hsh(hsh) click to toggle source
# File lib/abrupt/converter.rb, line 45
def init_hsh(hsh)
  hsh = Hash.from_xml(File.read(hsh)) unless hsh.is_a?(Hash)
  @hsh = hsh.deep_symbolize_keys
  return unless @hsh[:website]
  @hsh[:website][:url].each_with_index do |value, i|
    Transformation::Website::Base.subclasses.each do |transformation_class|
      @hsh[:website][:url][i] =
          transformation_class.customize_to_schema(value)
    end
  end
end
init_website() click to toggle source
# File lib/abrupt/converter.rb, line 39
def init_website
  domain = RDF::URI("#{VOC}Website/#{@uri}")
  @result << Statement.new(domain, RDF.type, VOC.Website)
  @result << Statement.new(domain, VOC.hostName, @uri.host)
end
perform() click to toggle source
# File lib/abrupt/converter.rb, line 69
def perform
  website = ['Website', @uri.to_s]
  @hsh[:website][:url].each do |url|
    page = ['Page', url[:name].append_last_slash]
    page_transformator = Transformation::Base.new(website, page)
    add_to_result page_transformator.add_individuals # add Page
    next unless url[:state]
    perform_states url[:state], website + page
  end
end
perform_states(states, parent_uri) click to toggle source
# File lib/abrupt/converter.rb, line 80
def perform_states(states, parent_uri)
  states = states.is_a?(Array) ? states : [states]
  states.each do |value|
    state = ['State', value[:name]]
    # MAYBE empty?
    add_to_result Transformation::Base.new(parent_uri, state).result
    Transformation::Website::Base.subclasses.each do |transformation_class|
      t = transformation_class.new(parent_uri + state, nil, value)
      add_to_result t.add_individuals
    end
  end
end