Module: WIKI

Defined in:
lib/meiou/wiki.rb

Defined Under Namespace

Classes: Gps, W

Constant Summary collapse

@@GPS =
Hash.new { |h,k| h[k] = Gps.new(k) }
@@W =
Hash.new { |h,k| h[k] = W.new(k) }
@@WIKI =
Hash.new do |h,k|
  a, x = [], @@W[k.to_s]
  if x[:text] == nil
    s = Wikipedia.find(k.to_s)
    if s != nil
      %[#{s.summary}].split("\n").each { |e|
        if !/^=+/.match(e)
          a << %[#{e}]
        end
      }
      aa = []; a.join("\n").split(/\n+/).each { |e| aa << e.gsub('"',"'").gsub(/\s+/," ").strip }
      x[:text] = aa.join("\n\n")
      x[:url] = s.fullurl
      x[:edit] = s.editurl
      cc, c = [], [];
      [s.categories].flatten.each { |e| if e != nil; cc << e.gsub("Category:",""); end }
      cc.each { |e|
        if !/^All articles/.match(e) && !/^Articles/.match(e) && !/^Coordinates on/.match(e) && !/^Short description is/.match(e)
          c << e
        end
      }
      x[:categories] = c.join("\n\n")
      
      x[:google] = "https://www.google.com/search?q=#{k.gsub(" ","+")}"
      
      x[:map] = "https://www.google.com/maps/place/#{k.gsub(" ","+")}"
      
      xx = s.coordinates
      
      if xx != nil
        x[:lat] = xx[0]
        x[:lon] = xx[1]
        g = @@GPS[k.to_s]
        g[:lat] = xx[0]
        g[:lon] = xx[1]
        g[:map] = x[:map]
        g[:google] = x[:google]
        g[:edit] = x[:edit]
        g[:url] = x[:url]
        g[:text] = x[:text]          
      end
    end
    h[k] = x
  end
end

Class Method Summary collapse

Class Method Details

.[](k) ⇒ Object



105
106
107
# File 'lib/meiou/wiki.rb', line 105

def self.[] k
  @@WIKI[k]
end

.gpsObject



39
40
41
# File 'lib/meiou/wiki.rb', line 39

def self.gps
  @@GPS
end

.keysObject



108
109
110
# File 'lib/meiou/wiki.rb', line 108

def self.keys
  @@WIKI.keys
end

.to_hObject



111
112
113
# File 'lib/meiou/wiki.rb', line 111

def self.to_h
  @@WIKI
end